SRL Archive - OSR Help

Need help freeing bitmaps


bud_wis_er_420

2013-04-30 01:01:07

Ok in one of my scripts I need to free some bitmaps. Problem is, the name of the bitmaps change according to the user settings. I have a sting array with the names of the bitmaps. But how do I use strings to do this?

Here is an example of my code, but obviously it don't work cause ItemsNeed is a TStringArray and won't convert to a Integer. But How WOULD I do this?


ItemsNeed: TStringArray;
procedure FreeAll;
var
i: Integer;
begin
for i := 0 to High(ItemsNeed) do
begin
writeln(ItemsNeed[i]);
if (DTMExists(StrToInt(ItemsNeed[i]))) then
FreeDTM(StrToInt(ItemsNeed[i]));
if (BitmapExists(StrToInt(ItemsNeed[i]))) then
FreeBitmap(StrToInt(ItemsNeed[i]));
end;
end;

Haxz

2013-04-30 01:06:51

Mmmm… What about making an array of integers instead of strings?

bud_wis_er_420

2013-04-30 01:33:22

I was trying to use a variable I already had available. And besides Like I said they change. I would have to hard code a case for each type of bmp and dtm, which is what I'm trying to avoid.

bud_wis_er_420

2013-05-01 01:35:54

Still looking for a way to use a string to free a dtm and bmp. So lets say I have a bmp named 'Gold.bmp'. I need a way to use 'Gold' as a string to free the bmp.

Le Jingle

2013-05-01 02:40:54

DTM's / BMP's are stored as integer's in pascalscript. You can't check if either exists via a string, or an element in a string array, as that is checking for an un-attached, non-existent, floating in and out of nowhere BMP/DTM.
Therefore you'd need to use an already specified integer type that was previously stored as a BMP/DTM.

For example


var values: TIntegerArray;
var names: TStringArray;
var i: Integer;

begin
// Initialize
SetArrayLength(values, 10);
SetArrayLength(names, 10);

names := ['1', '2', '3', '4', '5', '6', '7', '8', '9', '23412341234'];

// Create/Assign
for i := 0 to 9 do
begin
values[i] := BitmapFromString(10, 10, '');
SetBitmapName(values[i], string(names[i]) + '.bmp');
end;

for i := 0 to 9 do
begin
FreeBitmap(values[i]);

// attempting this would not work
{
FreeBitmap(BitmapFromString(10, 10, ''));
}
// Because you're trying to create a bitmap that floats in and out of existence
// this bitmap is being created. it is then free. that's it

end;
end.

Cheers,
LJ

bud_wis_er_420

2013-05-01 02:45:12

Hmm thx for clarifying that for me.