Solved

saving and loading problem

Posted on 1998-04-06
3
140 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
[X]
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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month4 days, 3 hours left to enroll

630 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