unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function WriteSamFile(const Buffer;WriteLen:integer;FilePath:string):Boolean;//<<<<<<<<
var
sf:TFileStream;
begin
try
sf:=TFileStream.Create(FilePath,fmOpenWrite);
sf.Position := sf.Seek(0,soFromBeginning);
sf.Write(Buffer,WriteLen);
result :=True;
finally
sf.free;
end;
end;
Function ReadSamFile(var Buffer;ReadLen:integer;FilePath:string):Boolean;
var
sf:TFileStream;
begin
try
sf:=TFileStream.Create(FilePath,fmOpenRead);
sf.Position :=Sf.Seek(0,soFromBeginning);
sf.Read(buffer,ReadLen);
result := True;
finally
sf.Free;
end;
end;
type
MyType = record
x,y:Integer;
end;
TextSetup = record
Windows:MyType;
State:Boolean;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
test:TextSetup;
begin
test.State := True;
test.Windows.x := 200;
test.Windows.y := 400;
WriteSamFile(Test,sizeof(TextSetup),'c:/temp/test.Bin');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
GetData:textsetup;
begin
Readsamfile(GetData,sizeof(textsetup),'c:/temp/test.Bin');
showmessage('x:' + inttostr(GetData.Windows.x) + ' y:'
+ Inttostr(GetData.Windows.y));
end;
end.