saving and loading problem

Posted on 1998-04-06
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.
Question by:SABOG7
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

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

  s : TFileStream;
  s := TFileStream.Create ('thefile', fmCreate);
    s.WriteComponent (Label1);
    s.WriteComponent (Image1);

for read the components simply do:

  s : TFileStream;
  s := TFileStream.Create ('thefile', fmOpenRead);
    s.ReadComponent (Label1);
    s.ReadComponent (Image1);

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.


Author Comment

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......

Expert Comment

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!!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically Created Query 3 79
Breakpoint doesn't stop in my variable 3 48
migrate this code to work on android 1 45
Way to create an iPhone app for my customers 8 89
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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