mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-30 04:52:05 +01:00
rtl: don't crash if resource is not found in TResourceStream and was passed by ID instead of Name (in this case exception tried to get a string from ID)
git-svn-id: trunk@17173 -
This commit is contained in:
parent
9ae0414dda
commit
812a665cbe
@ -926,7 +926,7 @@ type
|
|||||||
private
|
private
|
||||||
Res: TFPResourceHandle;
|
Res: TFPResourceHandle;
|
||||||
Handle: THandle;
|
Handle: THandle;
|
||||||
procedure Initialize(Instance: THandle; Name, ResType: PWideChar);
|
procedure Initialize(Instance: THandle; Name, ResType: PWideChar; NameIsID: Boolean);
|
||||||
public
|
public
|
||||||
constructor Create(Instance: THandle; const ResName: WideString; ResType: PWideChar);
|
constructor Create(Instance: THandle; const ResName: WideString; ResType: PWideChar);
|
||||||
constructor CreateFromID(Instance: THandle; ResID: Integer; ResType: PWideChar);
|
constructor CreateFromID(Instance: THandle; ResID: Integer; ResType: PWideChar);
|
||||||
@ -937,7 +937,7 @@ type
|
|||||||
private
|
private
|
||||||
Res: TFPResourceHandle;
|
Res: TFPResourceHandle;
|
||||||
Handle: THandle;
|
Handle: THandle;
|
||||||
procedure Initialize(Instance: THandle; Name, ResType: PChar);
|
procedure Initialize(Instance: THandle; Name, ResType: PChar; NameIsID: Boolean);
|
||||||
public
|
public
|
||||||
constructor Create(Instance: THandle; const ResName: string; ResType: PChar);
|
constructor Create(Instance: THandle; const ResName: string; ResType: PChar);
|
||||||
constructor CreateFromID(Instance: THandle; ResID: Integer; ResType: PChar);
|
constructor CreateFromID(Instance: THandle; ResID: Integer; ResType: PChar);
|
||||||
|
|||||||
@ -772,49 +772,61 @@ end;
|
|||||||
{****************************************************************************}
|
{****************************************************************************}
|
||||||
|
|
||||||
{$ifdef UNICODE}
|
{$ifdef UNICODE}
|
||||||
procedure TResourceStream.Initialize(Instance: THandle; Name, ResType: PWideChar);
|
procedure TResourceStream.Initialize(Instance: THandle; Name, ResType: PWideChar; NameIsID: Boolean);
|
||||||
begin
|
begin
|
||||||
Res:=FindResource(Instance, Name, ResType);
|
Res:=FindResource(Instance, Name, ResType);
|
||||||
if Res=0 then
|
if Res=0 then
|
||||||
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
if NameIsID then
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[IntToStr(PtrInt(Name))])
|
||||||
|
else
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
||||||
Handle:=LoadResource(Instance,Res);
|
Handle:=LoadResource(Instance,Res);
|
||||||
if Handle=0 then
|
if Handle=0 then
|
||||||
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
if NameIsID then
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[IntToStr(PtrInt(Name))])
|
||||||
|
else
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
||||||
SetPointer(LockResource(Handle),SizeOfResource(Instance,Res));
|
SetPointer(LockResource(Handle),SizeOfResource(Instance,Res));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TResourceStream.Create(Instance: THandle; const ResName: WideString; ResType: PWideChar);
|
constructor TResourceStream.Create(Instance: THandle; const ResName: WideString; ResType: PWideChar);
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
Initialize(Instance,PWideChar(ResName),ResType);
|
Initialize(Instance,PWideChar(ResName),ResType,False);
|
||||||
end;
|
end;
|
||||||
constructor TResourceStream.CreateFromID(Instance: THandle; ResID: Integer; ResType: PWideChar);
|
constructor TResourceStream.CreateFromID(Instance: THandle; ResID: Integer; ResType: PWideChar);
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
Initialize(Instance,PWideChar(ResID),ResType);
|
Initialize(Instance,PWideChar(ResID),ResType,True);
|
||||||
end;
|
end;
|
||||||
{$else UNICODE}
|
{$else UNICODE}
|
||||||
|
|
||||||
procedure TResourceStream.Initialize(Instance: THandle; Name, ResType: PChar);
|
procedure TResourceStream.Initialize(Instance: THandle; Name, ResType: PChar; NameIsID: Boolean);
|
||||||
begin
|
begin
|
||||||
Res:=FindResource(Instance, Name, ResType);
|
Res:=FindResource(Instance, Name, ResType);
|
||||||
if Res=0 then
|
if Res=0 then
|
||||||
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
if NameIsID then
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[IntToStr(PtrInt(Name))])
|
||||||
|
else
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
||||||
Handle:=LoadResource(Instance,Res);
|
Handle:=LoadResource(Instance,Res);
|
||||||
if Handle=0 then
|
if Handle=0 then
|
||||||
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
if NameIsID then
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[IntToStr(PtrInt(Name))])
|
||||||
|
else
|
||||||
|
raise EResNotFound.CreateFmt(SResNotFound,[Name]);
|
||||||
SetPointer(LockResource(Handle),SizeOfResource(Instance,Res));
|
SetPointer(LockResource(Handle),SizeOfResource(Instance,Res));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TResourceStream.Create(Instance: THandle; const ResName: string; ResType: PChar);
|
constructor TResourceStream.Create(Instance: THandle; const ResName: string; ResType: PChar);
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
Initialize(Instance,pchar(ResName),ResType);
|
Initialize(Instance,pchar(ResName),ResType,False);
|
||||||
end;
|
end;
|
||||||
constructor TResourceStream.CreateFromID(Instance: THandle; ResID: Integer; ResType: PChar);
|
constructor TResourceStream.CreateFromID(Instance: THandle; ResID: Integer; ResType: PChar);
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
Initialize(Instance,pchar(PtrInt(ResID)),ResType);
|
Initialize(Instance,pchar(PtrInt(ResID)),ResType,True);
|
||||||
end;
|
end;
|
||||||
{$endif UNICODE}
|
{$endif UNICODE}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user