Daniel
2010-04-16 00:39:53
I got the FreeAll method done and whatnot.
Preliminary methods that should be in SCAR/Simba/SRL (only the first method (DeleteArrayIndex_Int) is required for my part to work):
And the MSI methods:
Preliminary methods that should be in SCAR/Simba/SRL (only the first method (DeleteArrayIndex_Int) is required for my part to work):
{ Preliminary methods that should be included in (SCAR/Simba)/SRL }
// Made by Dan's The Man. Deletes specified Index from array and pushes to the left, reducing the length of the array by 1.
procedure DeleteArrayIndex_Int(var Arr: array of Integer; Index: Integer);
var
I, bI: Integer;
begin
bI := High(Arr) - 1;
if(not(InRange(Index, Low(Arr), bI + 1))) then
srl_Warn('DeleteArrayIndex_Int', 'Index (' + IntToStr(Index) + ') out of array range', warn_AllVersions);
for i := Index to bI do
Arr[i] := Arr[i + 1];
SetLength(Arr, bI + 1);
end;
procedure DeleteArrayIndex_Real(var Arr: array of Extended; Index: Integer);
var
I, bI: Integer;
begin
bI := High(Arr) - 1;
if(not(InRange(Index, Low(Arr), bI + 1))) then
srl_Warn('DeleteArrayIndex_Real', 'Index (' + IntToStr(Index) + ') out of array range', warn_AllVersions);
for i := Index to bI do
Arr[i] := Arr[i + 1];
SetLength(Arr, bI + 1);
end;
procedure DeleteArrayIndex_Str(var Arr: array of String; Index: Integer);
var
I, bI: Integer;
begin
bI := High(Arr) - 1;
if(not(InRange(Index, Low(Arr), bI + 1))) then
srl_Warn('DeleteArrayIndex_Str', 'Index (' + IntToStr(Index) + ') out of array range', warn_AllVersions);
for i := Index to bI do
Arr[i] := Arr[i + 1];
SetLength(Arr, bI + 1);
end;
procedure DeleteArrayIndex_Bool(var Arr: array of Boolean; Index: Integer);
var
I, bI: Integer;
begin
bI := High(Arr) - 1;
if(not(InRange(Index, Low(Arr), bI + 1))) then
srl_Warn('DeleteArrayIndex_Bool', 'Index (' + IntToStr(Index) + ') out of array range', warn_AllVersions);
for i := Index to bI do
Arr[i] := Arr[i + 1];
SetLength(Arr, bI + 1);
end;
And the MSI methods:
{ Constants defining loading and freeing methods of objects.
Purpose is self-explanatory }
const
MSI_Load_DTM = 0;
MSI_Load_Bitmap = 1;
MSI_Free_DTMsOnly = 0;
MSI_Free_BitmapsOnly = 1;
MSI_Free_All = 2;
{ The array which all MSI object are stored.
Supposed to be untouched by user/scripter }
var
LoadedInMemory: array[0..1] of array of Integer;
{******************************************************************************}
{ function MSIFromString(const WhatType: Byte; Str: String; warn_Type: }
{ ShortInt): Integer; }
{ By: Dan's The Man }
{ Description: Loads' an object into memory. }
{******************************************************************************}
function MSIFromString(const WhatType: Byte; Str: String; warn_Type: ShortInt): Integer;
var
ArrLnth: Integer;
begin
case (WhatType) of
0: Result := DTMFromString(Str);
1: Result := BitmapFromString2(True, Str);
else begin
Result := -1;
srl_Warn('MSIFromString', 'Invalid type identifier', warn_Type);
exit;
end;
end;
ArrLnth := Length(LoadedInMemory[WhatType]);
SetLength(LoadedInMemory[WhatType], ArrLnth + 1);
LoadedInMemory[WhatType][ArrLnth] := Result;
end;
{******************************************************************************}
{ procedure MSIFree(const WhatType: Byte; Handle: Integer; }
{ warn_Type: ShortInt); }
{ By: Dan's The Man }
{ Description: Frees' specified object from memory. }
{******************************************************************************}
procedure MSIFree(const WhatType: Byte; Handle: Integer; warn_Type: ShortInt);
var
Index, ArrLnth: Integer;
begin
if(not(InRange(WhatType, MSI_Free_DTMsOnly, MSI_Free_BitmapsOnly))) then
srl_Warn('MSIFree', 'Invalid type identifier to free', warn_Type);
ArrLnth := Length(LoadedInMemory[WhatType]);
for Index := (ArrLnth - 1) downto -1 do
if(LoadedInMemory[WhatType][Index] = Handle) then
break;
if(Index = -1) then
srl_Warn('MSIFree', 'Unable to find Handle in array. Will free normally.', warn_Warning) else
DeleteArrayIndex_Int(LoadedInMemory[WhatType], Index);
case (WhatType) of
0: FreeDTM(Handle);
1: FreeBitmap(Handle);
end;
end;
{******************************************************************************}
{ procedure MSIFreeAll(const WhatType: Byte; warn_Type: ShortInt); }
{ By: Dan's The Man }
{ Description: Frees' specified objects' type from memory. }
{******************************************************************************}
procedure MSIFreeAll(const WhatType: Byte; warn_Type: ShortInt);
var
i, bI, Count, _To: Integer;
begin
if(WhatType = 1) then
Count := 1 else
Count := 0;
if(WhatType = 2) then
_To := 1 else
_To := WhatType;
while (Count <= _To) do
begin
bI := High(LoadedInMemory[Count]);
for i := bI downto 0 do
MSIFree(Count, i, warn_Type);
Inc(Count);
end;
end;