troubleshooting Question

reading and writing a dat file to save data

Avatar of fiveuk
fiveuk asked on
Delphi
13 Comments2 Solutions227 ViewsLast Modified:
I been trying to read and right info in to a dat file to hold the selected font Color,Name and Size but it dont save them or load them so am wondering if anyone can help fix my code?

[Write code]
procedure TChatForm.FormDestroy(Sender: TObject);
var
c,b,f:byte;
begin
tempstr.Free;
b:=0;
tmpstr.Clear;
tmpstr.write(FB,1);
tmpstr.write(FI,1);
b := SizeBox.ItemIndex;
f := FontBox1.ItemIndex;
c := Colour.SelectedColour;
tmpstr.write(b,1);
tmpstr.Write(f,2);
tmpstr.Write(c,3);
tmpstr.write(UserColor[1],7);
tmpstr.SaveToFile(GetProgrammDir+'Data\chatcolor.dat');
tmpstr.free;
SendStream.Free;
GetStream.Free;
end;
[/code end]

next part is the load code

[load dat code]
procedure TChatForm.FormShow(Sender: TObject);
var
b,f,c:byte;
begin
  if FileExists(GetProgrammDir+'Data\chatcolor.dat') then
   begin
    tmpstr.Clear;
    tmpstr.LoadFromFile(GetProgrammDir+'Data\chatcolor.dat');
    tmpstr.Position:=1;
    tmpstr.Read(b,1);
    tmpstr.Read(f,2);
    tmpstr.Read(c,3);
    Colour.SelectedColour:=c;
    FontBox1.ItemIndex:=f;
    SizeBox.ItemIndex:=b;
    tmpstr.Position:=2;
    tmpstr.Read(FB,1);
    tmpstr.Position:=3;
    tmpstr.Read(FI,1);
    tmpstr.Position:=4;
    tmpstr.Position:=5;
    Setlength(UserColor,7);
    tmpstr.Read(UserColor[1],7);
    tmpstr.Clear;
[end code]


hope sumone can help me cheers
ASKER CERTIFIED SOLUTION
mokule

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros