Solved

saving and loading problem

Posted on 1998-04-06
3
136 Views
Last Modified: 2012-05-04
how can u save a Tlabel and a timage at the same file using savetofile method and can load the same file with the timageand tlabel and its original properties like the font color, the font style etc. can anybody give a sample code for this problem.
0
Comment
Question by:SABOG7
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
extreme earned 50 total points
ID: 1361314
Youy need to use streams for this. You have to do someting like this:

var
  s : TFileStream;
begin
  s := TFileStream.Create ('thefile', fmCreate);
  try
    s.WriteComponent (Label1);
    s.WriteComponent (Image1);
  finally
    s.Free;
  end;
end;

for read the components simply do:

var
  s : TFileStream;
begin
  s := TFileStream.Create ('thefile', fmOpenRead);
  try
    s.ReadComponent (Label1);
    s.ReadComponent (Image1);
  finally
    s.Free;
  end;
end;

the code above will work if the Label1 and Image1 are created, if not the you should assignt the value of ReadComponent to it and pass a nil parameter to readcomponent, something like this:

Label1 := s.ReadComponent (nil);

that line created in component, as contrary to

s.ReadComponent (Label1)

that load the contents of the label stored in the stream in the label already create.

Is important to make you note that in order to make this work you have to register the clases TLabel and TImage first. This ciuld be dont in the OnCreate event handler of your main form, or in the initialization part of some unit.

The code to register the classes is:

RegisterClass (TLabel);
REgisterclass (TImage);

If you have some problem with the registerclass method could be because you have the Windows unit declared after than the Classes unit. In such case write:

Classes.RegisterClass (TLabel);
Classes.Registerclass (TImage);

That should work.

0
 

Author Comment

by:SABOG7
ID: 1361315
you got an extreme answear. its very simple and accurate. were did you learn how to do that master EXREME. UR THE BEST .....thank you very very much.. from now on u r my IDOL....

from asher of the philippines......
0
 
LVL 1

Expert Comment

by:extreme
ID: 1361316
Thanks for your praises, :). I'm from Argentina, and I learned most I know simply programming, as you can do. Anyway I readed some book to increase my skills in some matters non well documented.

Salutes from here!!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question