Also weiter. Ich habe das Prinzip jetzt gerallt
Aber beim asulesen kommt noch was falsches zurück.
Delphi-Quellcode:
type
TConnection=record
user,pass,host:string;
port:integer;
auth:boolean;
end;
//speichern:
procedure TFormMain.Button1Click(Sender: TObject);
var
Stream: TStream;
begin
Connect_info.user:=edit7.text;
Connect_info.pass:=edit8.text;
Connect_info.host:=edit9.text;
Connect_info.port:=strtoint(edit10.text);
Connect_info.auth:=CheckBox1.enabled;
Stream := TFileStream.Create('h:\Connection.info', fmCreate or fmOpenWrite);
try
Stream.Write(Connect_info.user, SizeOf(Connect_info.user)+10);
Stream.Write(Connect_info.pass, SizeOf(Connect_info.pass)+10);
Stream.Write(Connect_info.host, SizeOf(Connect_info.host)+10);
Stream.Write(Connect_info.port, SizeOf(Connect_info.port)+10);
Stream.Write(Connect_info.auth, SizeOf(Connect_info.auth)+10);
finally
Stream.Free;
end;
//edits leeren und variablen verfälschen. Mache ich nur formal, damit man sieht wenn es NICHT klappt :)
edit7.text:='';
edit8.text:='';
edit9.text:='';
edit10.text:='';
Connect_info.user:='XX';
Connect_info.pass:='XX';
Connect_info.host:='XX';
Connect_info.port:=666;
Connect_info.auth:=false;
end;
//laden:
procedure TFormMain.Button2Click(Sender: TObject);
var Stream: TStream;
begin
Stream := TFileStream.Create('h:\Connection.info', fmOpenRead);
try
Stream.Position:=0; //<-- überflüssig hier
Stream.Read(Connect_info.user, SizeOf(Connect_info.user)+10);
Stream.Read(Connect_info.pass, SizeOf(Connect_info.pass)+10);
Stream.Read(Connect_info.host, SizeOf(Connect_info.host)+10);
Stream.Read(Connect_info.port, SizeOf(Connect_info.port)+10);
Stream.Read(Connect_info.auth, SizeOf(Connect_info.auth)+10);
finally
Stream.Free;
end;
//Variablen in edits ausgeben
edit7.text:=Connect_info.user;
edit8.text:=Connect_info.pass;
edit9.text:=Connect_info.host;
edit10.text:=inttostr(Connect_info.port);
edit2.text:=inttostr(SizeOf(Connect_info.user));
end;
Aber in den Edits steht hinter den eigentlich inhalten iemr noch ein zeichen doer sie sind unvollständig... Testet es selber. Nachher schicke ich noch ein screen vielleich. Geht jetzt nicht bin in der Schule.