unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, StdCtrls;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
procedure PrepareFile;
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CreateConfigFile: TStrings;
var
ConfigFile: TStrings;
begin
ConfigFile := TStringList.Create;
ConfigFile.Add('
ZAHL=');
// usw. ConfigFile.Add('WEITERE_INFO=');
Result := ConfigFile;
//ConfigFile.Destroy;
end;
function TMainFormPrepareConfigFile: TStrings;
var
ConfigFile: TStrings;
begin
ConfigFile := TStringList.Create;
ConfigFile.AddStrings(CreateConfigFile);
ConfigFile.Strings[0] := ConfigFile.Strings[0] + '
Edit1.Text';
// usq. ConfigFile.Strings[1] := ConfigFile.Strings[1] + 'Info 2';
Result := ConfigFile;
end;
function TMainFormPrepareServer(aFileName, aNewFileName:
String; aConfigFileText: TStrings): Boolean;
var
OrigFile, ConfigFile, NewFile: TFileStream;
ConfigFileText: TStrings;
OrigFileSize, ConfigFileSize: Integer;
begin
NewFile := TFileStream.Create(aNewFileName, fmOpenWrite);
OrigFileSize := 100;
NewFile.Seek(OrigFileSize, soFromBeginning);
SetEndOfFile(NewFile.Handle);
//ConfigFile als Text öffnen und aus den Infos ein neues erstellen
ConfigFileText := TStringList.Create;
ConfigFileText.Assign(aConfigFileText);
//ConfigFile an den Server anhängen
ConfigFileText.Insert(0, '
SELF=' + IntToStr(OrigFileSize));
ConfigFileText.SaveToFile(ExtractFilePath('
aNewServerName') + '
TempFile.conf');
ConfigFileText.Free;
ConfigFile := TFileStream.Create(ExtractFilePath(aNewFileName) + '
TempFile.conf', fmOpenRead);
ConfigFileSize := ConfigFile.Size;
NewFile.CopyFrom(ConfigFile, 0);
NewFile.
Write(ConfigFileSize, 4);
ConfigFile.Free;
NewFile.Free;
DeleteFile(ExtractFilePath(aNewFileName) + '
TempFile.conf');
Result := True;
end;
function TMainFormLoadConfigFile(aFileName:
String; Loaded: Boolean): Boolean;
var
aFile, ConfigFile: TFileStream;
ConfigFileText: TStrings;
ConfigFileSize: Integer;
TempStr:
String;
SelfSize:Integer;
begin
aFile := TFileStream.Create('
aServerName', fmShareExclusive);
ConfigFile := TFileStream.Create('
File.conf', fmCreate);
aFile.Seek(-4, soFromEnd);
aFile.
Read(ConfigFileSize, 4);
aFile.Seek(-4 - ConfigFileSize, soFromEnd);
ConfigFile.CopyFrom(aFile, ConfigFileSize);
ConfigFile.Free;
aFile.Free;
ConfigFileText := TStringList.Create;
ConfigFileText.LoadFromFile('
File.conf');
DeleteFile('
File.conf');
if Pos('
SELF=', ConfigFileText[0]) > 0
then
begin
TempStr := ConfigFileText[0];
Delete(TempStr, Pos('
SELF=', TempStr), 5);
SelfSize := 100;
end;
ConfigFileText.Delete(0);
// Daten auslesen
ConfigFileText.Delete(0);
// usw.
ConfigFileText.Free;
Result := True;
end;
procedure TForm1.PrepareFile;
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PrepareFile;
end;
end.