}

Delphi.int.ru — Портал программистов

Вход Регистрация | Забыли пароль?

Просмотр кода

Идентификатор: 44741ffe Описание: Код загружен: 12 августа 2011, 13:16 (min@y™)

unit uXmlUtils;
 
interface
 
uses
  SysUtils, Graphics, ECXMLParser;
 
// --------------- Добавление информации в XML -----------------
procedure XmlA
procedure XmlAddStringParam(ANode: TXMLItem; const Name, Value: string);
procedure XmlAddIntegerParam(ANode: TXMLItem; const Name: string; const Value: Integer);
procedure XmlAddCardinalParam(ANode: TXMLItem; const Name: string; const Value: Cardinal);
procedure XmlAddColorParam(ANode: TXMLItem; const Name: string; const Value: TColor);
procedure XmlAddBoolParam(ANode: TXMLItem; const Name: string; const Value: Boolean);
procedure XmlAddTimeParam(ANode: TXMLItem; const Name: string; const Value: TDateTime);
procedure XmlAddDateParam(ANode: TXMLItem; const Name: string; const Value: TDateTime);
procedure XmlAddDateTimeParam(ANode: TXMLItem; const Name: string; const Value: TDateTime);
procedure XmlAddFloatParam(ANode: TXMLItem; const Name: string; const Value: Extended);
procedure XmlAddFontStyleParam(ANode: TXMLItem; const Name: string; const Value: TFontStyles);
 
//иск и извлечение информации из XML -----------
function XmlFindParam(ANode: TXMLIt
function XmlFindParam(ANode: TXMLItem; const Name: string): Integer;
function XmlFindNodeIndex(AParentNode: TXMLItem; const Name: string): Integer;
function XmlFindNode(AParentNode: TXMLItem; const Name: string): TXMLItem;
 
function XmlGetStringParam(ANode: TXMLItem; const Name, Default: string): string;
function XmlGetIntegerParam(ANode: TXMLItem; const Name: string; const Default: Integer): Integer;
function XmlGetCardinalParam(ANode: TXMLItem; const Name: string; const Default: Cardinal): Cardinal;
function XmlGetColorParam(ANode: TXMLItem; const Name: string; const Default: TColor): TColor;
function XmlGetBoolParam(ANode: TXMLItem; const Name: string; const Default: Boolean): Boolean;
function XmlGetTimeParam(ANode: TXMLItem; const Name: string; Default: TDateTime): TDateTime;
function XmlGetDateParam(ANode: TXMLItem; const Name: string; Default: TDateTime): TDateTime;
function XmlGetDateTimeParam(ANode: TXMLItem; const Name: string; Default: TDateTime): TDateTime;
function XmlGetFloatParam(ANode: TXMLItem; const Name: string; Default: Extended): Extended;
function XmlGetFontStyleParam(ANode: TXMLItem; const Name: string; Default: TFontStyles): TFontStyles;
 
//----------------
function FindNamedItem(AParentNode: TXMLItem;
function FindNamedItem(AParentNode: TXMLItem; const Name: string; const FromIndex: Integer = 0): TXMLItem;
function ReplaceIllegalSymbols(const S: string): string;
 
implementation
 
//-----------------
 
// Преобразование стилей шрифта в число
function FontStyle2Int(const AFontStyle: TF
 
//tyles): Integer;
var
  Style: TFontStyle;
begin
  Result:= 0;
 
  for Style:= Low(TFontStyle) to High(
var
  Style: TFontStyle;
begin
  Result:= 0;
 
  for Style:= Low(TFontStyle) to High(TFontStyle) do
    if Style in AFontStyle
      then Result:= Result or (1 shl Integer(Style));
end;
 
//yle: TFontStyle;
begin
  Result:= [];
 
  for Style:= Low(TFontStyle) to High(TFontStyle) do
    if iFontStyle and (1 shl Inte
begin
  Result:= [];
 
  for Style:= Low(TFontStyle) to High(TFontStyle) do
    if iFontStyle and (1 shl Integer(Style)) <> 0
      then Result:= Result + [Style];
end;
 
//e: string);
begin
  ANode.Params.Add(Name + '=' + Value);
end;
 
procedure XmlAddIntegerParam(ANode: TXMLItem; const Name: string; const
begin
  ANode.Params.Add(Name + '=' + Value);
end;
 
procedure XmlAddIntegerParam(ANode: TXMLItem; const Name: string; const Value: Integer);
begin
  ANode.Params.Add(Name + '=' + IntToStr(Value));
end;
 
procedure XmlAddCardinalParam(ANode: TXMLItem; const Name: string; const Value: Cardinal);
begin
  ANode.Params.Add(Name + '=' + IntToHex(Value, 8));
end;
 
procedure XmlAddColorParam(ANode: TXMLItem; const Name: string; const Value: TColor);
begin
  //e: TXMLItem; const Name: string; const Value: Boolean);
begin
  if Value
    then XmlAddStringParam(ANode, Name, '1')
    else XmlAddStringParam(ANode, Name, '0');
end;
 
procedure XmlAddTimeParam(ANode: 
begin
  if Value
    then XmlAddStringParam(ANode, Name, '1')
    else XmlAddStringParam(ANode, Name, '0');
end;
 
procedure XmlAddTimeParam(ANode: TXMLItem; const Name: string; const Value: TDateTime);
begin
  ANode.Params.Add(Name + '=' + TimeToStr(Value));
end;
 
procedure XmlAddDateParam(ANode: TXMLItem; const Name: string; const Value: TDateTime);
begin
  ANode.Params.Add(Name + '=' + DateToStr(Value));
end;
 
procedure XmlAddDateTimeParam(ANode: TXMLItem; const Name: string; const Value: TDateTime);
begin
  ANode.Params.Add(Name + '=' + DateTimeToStr(Value));
end;
 
procedure XmlAddFloatParam(ANode: TXMLItem; const Name: string; const Value: Extended);
begin
  ANode.Params.Add(Name + '=' + FloatToStr(Value));
end;
 
procedure XmlAddFontStyleParam(ANode: TXMLItem; const Name: string; const Value: TFontStyles);
begin
  ANode.Params.Add(Name + '=' + IntToStr(FontStyle2Int(Value)));
end;
 
//Name(Name);
end;
 
function XmlFindNodeIndex(AParentNode: TXMLItem; const Name: string): Integer;
begin
  Result:= AParentNode.IndexOfName(Name);
end;
 
function XmlFindNode(AParentN
end;
 
function XmlFindNodeIndex(AParentNode: TXMLItem; const Name: string): Integer;
begin
  Result:= AParentNode.IndexOfName(Name);
end;
 
function XmlFindNode(AParentNode: TXMLItem; const Name: string): TXMLItem;
var
  Index: Integer;
begin
  Result:= nil;
  Index:= AParentNode.IndexOfName(Name);
  if Index <> -1
    then Result:= AParentNode.SubItems[Index];
end;
 
function XmlGetStringParam(ANode: TXMLItem; const Name, Default: string): string;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
  if Index <> -1
    then Result:= ANode.Params.ValueFromIndex[Index]
    else Result:= Default;
 
  if Result = '""'
    then Result:= ''; //= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else if not TryStrToInt(ANode.Params.ValueFromIndex[Index], Result)
           then Result:= Default;
end;
 
function XmlGetCardinalParam(ANode: TXMLIt
 
  if Index = -1
    then Result:= Default
    else if not TryStrToInt(ANode.Params.ValueFromIndex[Index], Result)
           then Result:= Default;
end;
 
function XmlGetCardinalParam(ANode: TXMLItem; const Name: string; const Default: Cardinal): Cardinal;
var
  Index: Integer;
begin
  //))
           then Result:= Default;
end;
 
function XmlGetColorParam(ANode: TXMLItem; const Name: string; const Default: TColor): TColor;
var
  Index: Integer;
begin
  // Чтение параметра типа Param="11BBCC" (шестнадцатеричного)
  Index:= XmlFindPara
           then Result:= Default;
end;
 
function XmlGetColorParam(ANode: TXMLItem; const Name: string; const Default: TColor): TColor;
var
  Index: Integer;
begin
  //:= Default;
end;
 
function XmlGetBoolParam(ANode: TXMLItem; const Name: string; const Default: Boolean): Boolean;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else Result:= XmlGetStringParam(A
end;
 
function XmlGetBoolParam(ANode: TXMLItem; const Name: string; const Default: Boolean): Boolean;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else Result:= XmlGetStringParam(ANode, Name, '0') = '1';
end;
 
function XmlGetTimeParam(ANode: TXMLItem; const Name: string; Default: TDateTime): TDateTime;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else if not TryStrToTime(ANode.Params.ValueFromIndex[Index], Result)
           then Result:= Default;
end;
 
function XmlGetDateParam(ANode: TXMLItem; const Name: string; Default: TDateTime): TDateTime;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else if not TryStrToDate(ANode.Params.ValueFromIndex[Index], Result)
           then Result:= Default;
end;
 
function XmlGetDateTimeParam(ANode: TXMLItem; const Name: string; Default: TDateTime): TDateTime;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else if not TryStrToDateTime(ANode.Params.ValueFromIndex[Index], Result)
           then Result:= Default;
end;
 
function XmlGetFloatParam(ANode: TXMLItem; const Name: string; Default: Extended): Extended;
var
  Index: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else if not TryStrToFloat(ANode.Params.ValueFromIndex[Index], Result)
           then Result:= Default;
end;
 
function XmlGetFontStyleParam(ANode: TXMLItem; const Name: string; Default: TFontStyles): TFontStyles;
var
  Index, Temp: Integer;
begin
  Index:= XmlFindParam(ANode, Name);
 
  if Index = -1
    then Result:= Default
    else if TryStrToInt(ANode.Params.ValueFromIndex[Index], Temp)
           then Result:= Int2FontStyle(Temp)
           else Result:= Default;
end;
 
//Index:= FromIndex to AParentNode.Count - 1 do
    if AParentNode.SubItems[Index].Name = Name
      then begin
             Result:= AParentNode.SubItems[Index];
             Break;
           end;
end;
 
// Замена неподходящих для XML-имён символов на "_"
function ReplaceIllegalSymbols(const S: string): string;
const
  AllowedSymbols: set of Char = ['0'..'9', 
    if AParentNode.SubItems[Index].Name = Name
      then begin
             Result:= AParentNode.SubItems[Index];
             Break;
           end;
end;
 
//t) do
    if not (Result[Index] in AllowedSymbols)
      then Result[Index]:= '_';
end;
 
 
end.</code>
 

Ссылка на данный код:

На главную страницу сервиса обмена кодом »