Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Images One Form.

Status
Not open for further replies.

PANTLORD

Programmer
Aug 28, 2001
49
EU
Hi there,

I have a program which works but I'd like to change it significantly. Basically it displays pictures in a TImage control based on a number generated randomly by the press of a button. At the minute I am using code like this to display the various images;
Image1.Picture.LoadFromFile('C:\Temp\andy.bmp');
this is enclosed within an if loop and executed based on the integer 1 being returned others load different bitmaps on the return of a different number.

Is there any way that I can build all these bitmaps into the code at run time and then call them as I like or am I stuck having to make calls to external directories.

Thanks
PL
 
Have a read up on the searchrec, findfirst and findnext commands. Using these tools you can load the files in to a string list,
Some thing like:
function GetFileList(const Path: string): TStringList;
var
I: Integer;
SearchRec: TSearchRec;
begin
Result := TStringList.Create;
try
I := FindFirst(Path, 0, SearchRec);
while I = 0 do
begin
Result.Add(SearchRec.Name);
I := FindNext(SearchRec);
end;
except
Result.Free;
raise;
end;
end;
this code is an example for raising exceptions so it desn't work as it should( couldn't find the one I did that works), but it will give you the idea
 
If they're not very big you could put them in a resource file - that would be compiled into the program. Using the Borland image editor though, it looks like the biggest size is 768x768 pixels. TealWren
 
Place your image directories into a array list or vector like some programmers prefer to call them:

Image[1] := 'image1.bmp';
Image[2] := 'image2.bmp';
Image[3] := 'image3.bmp';
etc...

Use the index as your randomly generated number!

Image1.Picture.LoadFromFile(Image[Random(X)]);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top