Jump to content
spartakos

BitmapFromString in 3.40

Recommended Posts

For those who, like me, helplessly searched the forums on how to deal with old "bitmapFromString" function in 3.40, here's what I ultimately found.

 

Prior to 3.40 (in 3.38 and earlier) the SCAR had an option (under Tools menu) to convert all old BitmapFromString to the new TSCARBitmap.Create automatically!

 

Second. In SCAR 3.40 functions like BitmapFree and BitmapAssigned are also dropped. And memory is no more auto-magically freed after stopping the program. So, if you assign the result of an TSCARBitmap.Create to an integer (old-fashioned style), the memory will be lost in 100% cases. You can't possibly free it, and it won't be freed by itself!

 

So, I made a simple bmp manager of my own to solve the problem and not to rewrite half of the code. (Hint: This manager needs to be improved if you want not only to create, but to release some bmps in the process.)

 

var bmps : integer;
   bmpstorage: array of TScarBitmap;

function CreateBmp(data: string): integer;
begin
 if bmps > length(bmpstorage) - 1 then begin
   if bmps = 0 then setlength(bmpstorage, 10);
   else setlength(bmpstorage, bmps*2);
 end;

 bmpstorage[bmps] := TSCARBitmap.create(data);
 result := bmpstorage[bmps] as integer;
 inc(bmps);
End;

procedure ScriptTerminate;
var i: integer;
begin
 // launched by scar every time the script is stopped
 for i := 0 to bmps - 1 do begin
   bmpstorage[i].free;
 end;
end;

 

Then you can replace (Ctrl + R) all occurrences of TSCARBitmap.Create by the CreateBmp function.

Edited by georgri
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...