![]() |
Problem mit Resourcendatei
Hallo
ich versuche eine Komponente von Delphi7 auf Delphi 2010 umzusetzen. Bei der INITIALIZATION werden Resourcendateien verarbeitet. Diese Routine bekomme ich nicht in den Griff und freue mich über jeden Tip. Zur Info: Die Komponente wurde nicht von uns entwickelt, den Programmierer gibt es nicht mehr - lediglich diesen SourceCode ZumThema: Das Problem ist, dass beim Zugriff auf rRecord.Value eine Schutzverletzung auftritt. Der Debugger sagt "nicht verfügbarer Wert". Unter Delphi7 wird ein sauberer String zurückgeliefert. Habe bereits Char durch AnsiChar ersetzt aber ohne Änderung, poste hier aber der original Code. Vielen Dank für Eure Hilfe. UNIT1 --> der Aufruf
Delphi-Quellcode:
{$R SPQWORDS.R32}
{$IFDEF WINDOWS} PROCEDURE SPQ_FreeKeywords; FAR; BEGIN SPQ_Keywords.Free; END; {$ENDIF} INITIALIZATION SPQ_Keywords := TStringList.Create; LoadShazamResource('TspqKeywords', -1, SPQ_Keywords); {$IFDEF WINDOWS} AddExitProc(SPQ_FreeKeywords); {$ENDIF} {$IFDEF WIN32} FINALIZATION SPQ_Keywords.Free; {$ENDIF} UNIT2:
Delphi-Quellcode:
TYPE
{resource record structure} TspqRecord = ^TspqRecordType; TspqRecordType = RECORD Index :SmallInt; Value :String; END; FUNCTION LoadShazamResource(CONST sResource :String; iIndex :Integer; cList :TStrings) :String; VAR hLocation: THandle; hResource: THandle; rRecord: TspqRecord; pPointer: PChar; pResource :ARRAY[0..49] OF Char; bIsList :Boolean; BEGIN //set default result Result := ''; //convert resource name into pchar StrPCopy(pResource, sResource); //find location of resource within current instance of executable code hLocation := FindResource(hInstance, pResource, 'TspqResource'); IF hLocation = 0 THEN BEGIN RAISE Exception.CreateFmt('Error: Cannot find string resource [%s]', [sResource]); Exit; END; //load resource into memory hResource := LoadResource(hInstance, hLocation); IF hResource = 0 THEN BEGIN RAISE EOutOfResources.CreateFmt('Error: Cannot load string resource [%s]', [sResource]); Exit; END; //lock resource rRecord := LockResource(hResource); IF rRecord = NIL THEN BEGIN RAISE EOutOfResources.CreateFmt('Error: Cannot lock string resource [%s]', [sResource]); Exit; END; //determine list status bIsList := (cList <> NIL); //override index if list exists to finish processing on record 0, the last record IF bIsList THEN iIndex := 0; //start try..finally block TRY //start try..exception block TRY //load each record within the resource and process its values WHILE (rRecord <> NIL) AND (rRecord^.Index <> 0) AND (rRecord^.Index <> iIndex) DO BEGIN IF bIsList=True THEN cList.Add(rRecord^.Value); pPointer := PChar(rRecord); Inc(pPointer, SizeOf(SmallInt) + Length(rRecord^.Value) + 1); rRecord := TspqRecord(pPointer); END; //return a specific string if string list is nil IF bIsList = False THEN BEGIN IF (rRecord = NIL) OR (rRecord^.Value = '') THEN BEGIN RAISE Exception.CreateFmt('Error: String [%d] does not exist in resource [%s]', [iIndex, sResource]); END ELSE BEGIN Result := rRecord^.Value; END; END; EXCEPT ON E: Exception DO BEGIN MsgBox(E.Message, mtError, [mbOK]); END; END; FINALLY //unlock and free resource UnlockResource(hResource); FreeResource(hResource); END; END; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:07 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz