uses Resources;
// String in einer Stringtable
function ResourceExists(index: integer): Boolean; overload;
var
buffer: array[0..255] of Char;
s: string;
begin
result := false;
try
if LoadString(HInstance, index, buffer, SizeOf(buffer)) > 0 then
s := string(buffer);
result := s <> '';
except
on e:
exception do
Showmessage('Error ' + e.message);
end;
end;
// String in einer RCDATA-Resource
function ResourceExists(ResName: string): Boolean; overload;
var
lpResource: TPEResource;
resGroup: TPEResourceGroup;
begin
result := false;
resGroup := TPEResourceGroup.Create(HInstance, RT_RCDATA);
try
lpResource := resGroup.Find(pchar(resname));
if lpResource <> nil then result:=true;
finally
if Assigned(resGroup) then FreeAndNil(resGroup);
resGroup.Free;
end;
end;
function TForm1.GetResValue(resname: string): string;
var
RS: TResourceStream;
begin
RS := nil;
RS := TResourceStream.Create(hInstance, ResName, RT_RCDATA);
try
SetLength(result, RS.Size);
RS.Read(result[1], Length(result));
finally
RS.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ResName: string;
slResValue: TStringlist;
begin
ResName := 'liste'; // Name der RCDATA-Resource!
if ResourceExists(ResName) then
begin
slResValue:=TStringlist.Create;
try
slResValue.text := GetResValue(ResName);
Showmessage(format('Strings in der Resource "%s":'#13#10'%s', [ResName, slResValue.text]));
// ... und Stringlist nach Bedarf analysieren
finally
slResValue.Free;
end;
end
else
ShowMessage(format('RCDATA-Resource "%s" gibt es nicht!', [ResName]));
end;