Changed LResources to TLResources

Shane

git-svn-id: trunk@124 -
This commit is contained in:
lazarus 2001-01-16 16:21:29 +00:00
parent fa7e42fde5
commit b86d3c39a1
5 changed files with 44 additions and 41 deletions

View File

@ -220,11 +220,11 @@ function TIDEComponent.LoadImageIntoPixmap: TPixmap;
function LoadResource(ResourceName:string; PixMap:TPixMap):boolean; function LoadResource(ResourceName:string; PixMap:TPixMap):boolean;
var var
ms:TMemoryStream; ms:TMemoryStream;
res:LResource; res:TLResource;
begin begin
Result:=false; Result:=false;
res:=LazarusResources.Find(ResourceName); res:=LazarusResources.Find(ResourceName);
if (res.Value<>'') then begin if (res <> nil) then begin
if res.ValueType='XPM' then begin if res.ValueType='XPM' then begin
ms:=TMemoryStream.Create; ms:=TMemoryStream.Create;
try try

View File

@ -226,11 +226,11 @@ uses
function LoadResource(ResourceName:string; PixMap:TPixMap):boolean; function LoadResource(ResourceName:string; PixMap:TPixMap):boolean;
var var
ms:TMemoryStream; ms:TMemoryStream;
res:LResource; res:TLResource;
begin begin
Result:=false; Result:=false;
res:=LazarusResources.Find(ResourceName); res:=LazarusResources.Find(ResourceName);
if (res.Value<>'') then begin if (res = nil) or (res.Value<>'') then begin
if res.ValueType='XPM' then begin if res.ValueType='XPM' then begin
ms:=TMemoryStream.Create; ms:=TMemoryStream.Create;
try try
@ -1013,7 +1013,7 @@ Var
ResourceData : String; ResourceData : String;
I,A : Integer; I,A : Integer;
Instance : TComponent; Instance : TComponent;
CompResource : LResource; CompResource : TLResource;
Begin Begin
textFile := TStringList.Create; textFile := TStringList.Create;
TextFile.LoadFromFile(Value); TextFile.LoadFromFile(Value);
@ -1933,6 +1933,10 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.46 2001/01/16 16:21:29 lazarus
Changed LResources to TLResources
Shane
Revision 1.45 2001/01/15 20:55:44 lazarus Revision 1.45 2001/01/15 20:55:44 lazarus
Changes for loading filesa Changes for loading filesa
Shane Shane

View File

@ -954,11 +954,11 @@ constructor TSourceNotebook.Create(AOwner: TComponent);
function LoadResource(ResourceName:string; PixMap:TPixMap):boolean; function LoadResource(ResourceName:string; PixMap:TPixMap):boolean;
var var
ms:TMemoryStream; ms:TMemoryStream;
res:LResource; res:TLResource;
begin begin
Result:=false; Result:=false;
res:=LazarusResources.Find(ResourceName); res:=LazarusResources.Find(ResourceName);
if (res.Value<>'') then begin if (res = nil) or (res.Value<>'') then begin
if res.ValueType='XPM' then begin if res.ValueType='XPM' then begin
ms:=TMemoryStream.Create; ms:=TMemoryStream.Create;
try try

View File

@ -333,7 +333,7 @@ function InitResourceComponent(Instance: TComponent;
RootAncestor: TClass):Boolean; RootAncestor: TClass):Boolean;
function InitComponent(ClassType: TClass): Boolean; function InitComponent(ClassType: TClass): Boolean;
var CompResource:LResource; var CompResource:TLResource;
a:integer; a:integer;
begin begin
Result:=false; Result:=false;
@ -341,7 +341,7 @@ function InitResourceComponent(Instance: TComponent;
if Assigned(ClassType.ClassParent) then if Assigned(ClassType.ClassParent) then
Result:=InitComponent(ClassType.ClassParent); Result:=InitComponent(ClassType.ClassParent);
CompResource:=LazarusResources.Find(Instance.ClassName); CompResource:=LazarusResources.Find(Instance.ClassName);
if (CompResource.Value='') then exit; if (CompResource = nil) or (CompResource.Value='') then exit;
// Writeln('Compresource.value is '+CompResource.Value); // Writeln('Compresource.value is '+CompResource.Value);
if (ClassType.InheritsFrom(TForm)) if (ClassType.InheritsFrom(TForm))
and (CompResource.ValueType<>'FORMDATA') then exit; and (CompResource.ValueType<>'FORMDATA') then exit;

View File

@ -25,15 +25,15 @@ uses
Classes, SysUtils, Strings; Classes, SysUtils, Strings;
type type
PLResource = ^LResource; TLResource = class
LResource = record public
Name: AnsiString; Name: AnsiString;
ValueType: AnsiString; ValueType: AnsiString;
Value: AnsiString; Value: AnsiString;
end; end;
TLResourceList = class(TObject) TLResourceList = class(TObject)
private public //private
FList:TList; // main list with all resource pointer FList:TList; // main list with all resource pointer
FMergeList:TList; // list needed for mergesort FMergeList:TList; // list needed for mergesort
FSortedCount:integer; // 0 .. FSortedCount-1 resources are sorted FSortedCount:integer; // 0 .. FSortedCount-1 resources are sorted
@ -43,7 +43,7 @@ type
procedure Merge(List,MergeList:TList;Pos1,Pos2,Pos3:integer); procedure Merge(List,MergeList:TList;Pos1,Pos2,Pos3:integer);
public public
procedure Add(Name,ValueType,Value:AnsiString); procedure Add(Name,ValueType,Value:AnsiString);
function Find(Name:AnsiString):LResource; function Find(Name:AnsiString):TLResource;
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
end; end;
@ -225,56 +225,55 @@ end;
destructor TLResourceList.Destroy; destructor TLResourceList.Destroy;
var a:integer; var a:integer;
p:PLResource;
begin begin
for a:=0 to FList.Count-1 do begin for a:=0 to FList.Count-1 do
p:=FList[a]; TLResource(FList[a]).Free;
LResource(p^).Name:='';
LResource(p^).ValueType:='';
LResource(p^).Value:='';
FreeMem(p);
end;
FList.Free; FList.Free;
FMergeList.Free; FMergeList.Free;
end; end;
procedure TLResourceList.Add(Name,ValueType,Value:AnsiString); procedure TLResourceList.Add(Name,ValueType,Value:AnsiString);
var NewPLResource:PLResource; var
NewLResource:TLResource;
begin begin
GetMem(NewPLResource,SizeOf(LResource)); NewLResource:=TLResource.Create;
NewPLResource^.Name:=Name; NewLResource.Name:=Name;
NewPLResource^.ValueType:=uppercase(ValueType); NewLResource.ValueType:=uppercase(ValueType);
NewPLResource^.Value:=Value; NewLResource.Value:=Value;
FList.Add(NewPLResource); FList.Add(NewLResource);
end; end;
function TLResourceList.Find(Name:AnsiString):LResource; function TLResourceList.Find(Name:AnsiString):TLResource;
var p:integer; var p:integer;
begin begin
p:=FindPosition(Name); p:=FindPosition(Name);
if (p>=0) and (p<FList.Count) if (p>=0) and (p<FList.Count) and (AnsiCompareText(TLResource(FList[p]).Name,Name)=0) then
and (AnsiCompareText(LResource(FList[p]^).Name,Name)=0) then begin
Result:=LResource(FList[p]^) Result:=TLResource(FList[p]);
else begin end
Result.Name:=Name; else
Result.Value:=''; begin
Result.ValueType:=''; // Writeln('returning nil');
Result:=nil;
end; end;
end; end;
function TLResourceList.FindPosition(Name:AnsiString):integer; function TLResourceList.FindPosition(Name:AnsiString):integer;
var l,r,cmp:integer; var l,r,cmp:integer;
begin begin
if FSortedCount<FList.Count then Sort; if FSortedCount<FList.Count then
Sort;
Result:=-1; Result:=-1;
l:=0; l:=0;
r:=FList.Count-1; r:=FList.Count-1;
while (l<=r) do begin while (l<=r) do begin
Result:=(l+r) shr 1; Result:=(l+r) shr 1;
cmp:=AnsiCompareText(Name,LResource(FList[Result]^).Name); // Writeln(Format('l,r,Name,FList[Result].Name = %d,%d,%s,%s',[l,r,Name,TLResource(FList[Result]).Name]));
cmp:=AnsiCompareText(Name,TLResource(FList[Result]).Name);
if cmp<0 then if cmp<0 then
r:=Result-1 r:=Result-1
else if cmp>0 then else
if cmp>0 then
l:=Result+1 l:=Result+1
else else
exit; exit;
@ -298,7 +297,7 @@ begin
if Pos1=Pos2 then begin if Pos1=Pos2 then begin
end else if Pos1+1=Pos2 then begin end else if Pos1+1=Pos2 then begin
cmp:=AnsiCompareText( cmp:=AnsiCompareText(
LResource(List[Pos1]^).Name,LResource(List[Pos2]^).Name); TLResource(List[Pos1]).Name,TLResource(List[Pos2]).Name);
if cmp>0 then begin if cmp>0 then begin
MergeList[Pos1]:=List[Pos1]; MergeList[Pos1]:=List[Pos1];
List[Pos1]:=List[Pos2]; List[Pos1]:=List[Pos2];
@ -325,7 +324,7 @@ begin
DestPos:=Pos3; DestPos:=Pos3;
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
cmp:=AnsiCompareText( cmp:=AnsiCompareText(
LResource(List[Src1Pos]^).Name,LResource(List[Src2Pos]^).Name); TLResource(List[Src1Pos]).Name,TLResource(List[Src2Pos]).Name);
if cmp>0 then begin if cmp>0 then begin
MergeList[DestPos]:=List[Src1Pos]; MergeList[DestPos]:=List[Src1Pos];
dec(Src1Pos); dec(Src1Pos);