- Код: Выделить всё
unit fc_xml;
{$mode delphi}
interface
uses SysUtils, StrUtils, Classes, XMLConf;
//stdcalls
function fcxmlReadString (const AIdent, ADefault, AFileName: string): string; stdcall;
function fcxmlReadInteger (const AIdent: string; const ADefault: int64; const AFileName: string): int64; stdcall;
function fcxmlReadBoolean (const AIdent: string; const ADefault: boolean; const AFileName: string): boolean; stdcall;
procedure fcxmlWriteString (const AIdent, AValue, AFileName: string); stdcall;
procedure fcxmlWriteInteger (const AIdent: string; const AValue: integer; const AFileName: string); stdcall;
procedure fcxmlWriteBoolean (const AIdent: string; const AValue: boolean; const AFileName: string); stdcall;
procedure fcxmlDeleteItem (const AIdent, AKey, AFileName: string); stdcall;
implementation
//Special functions and procedures
//Read functions
function fcxmlReadString (const AIdent, ADefault, AFileName: string): string;
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
Result:= XML.GetValue(AIdent, ADefault);
XML.Free;
end;
function fcxmlReadInteger (const AIdent: string; const ADefault: int64; const AFileName: string): int64;
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
Result:= XML.GetValue(AIdent, ADefault);
XML.Free;
end;
function fcxmlReadBoolean (const AIdent: string; const ADefault: boolean; const AFileName: string): boolean;
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
Result:= XML.GetValue(AIdent, ADefault);
XML.Free;
end;
//Write procdures
procedure fcxmlWriteString (const AIdent, AValue, AFileName: string);
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
XML.RootName:= 'fcxml';
XML.SetValue(AIdent, AValue);
XML.Flush;
XML.Free;
end;
procedure fcxmlWriteInteger (const AIdent: string; const AValue: integer; const AFileName: string);
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
XML.RootName:= 'fcxml';
XML.SetValue(AIdent, AValue);
XML.Flush;
XML.Free;
end;
procedure fcxmlWriteBoolean (const AIdent: string; const AValue: boolean; const AFileName: string);
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
XML.RootName:= 'fcxml';
XML.SetValue(AIdent, AValue);
XML.Flush;
XML.Free;
end;
//Delete function
procedure fcxmlDeleteItem (const AIdent, AKey, AFileName: string);
var XML: TXMLConfig;
begin
XML:= TXMLConfig.Create(nil);
XML.Filename:= AFileName;
XML.RootName:= 'fcxml';
XML.DeletePath(AIdent);
XML.Flush;
XML.Free;
end;
end.
Но при попытке использовать его - ошибка (что-то там с RootName)...
Вот пример использования:
- Код: Выделить всё
fcxmlWriteString('Ex1/Ex2/Ex3/Value', 'Hello, guys 1!', 'D:\example.xml');
fcxmlWriteString('Ex1/Ex2/Ex3/Value2', 'Hello, guys 2!', 'D:\example.xml');
ShowMessage(fcxmlReadString('Ex1/Ex2/Ex3/Value1', 'UPS! ITs DEFAULT!!!', 'D:\example.xml'));
Что я делаю не так?