I appear to have created code that is trashing memory.
Having never had such problems before, i am now settign an Invalid Pointer Operation.
In the following the value of the const string sFilename gets trashed after my call to PromptForXYZPropertiesSettings.
// Allow the user to quickly display the properties of XYZ without needing to display the full Editor
function PromptForXYZProperties(const sFilename:string; var AXYZProperties: TXYZProperties): boolean;
var
PropEditor: TdlgEditor;
begin
PropEditor:= TdlgEditor.create(nil);
try
PropEditor.LoadFromFile(sFilename); <-- sFilename = 'C:\My Folder\Some Folder.txt'
PropEditor.SelectedXYZProperties := AXYZProperties;
// Bypass PropEditor to show form owned by it
Result := PropEditor.PromptForXYZPropertiesSettings;
if Result then
begin
PropEditor.SaveToFile(sFilename); <-- sFilename now somethign like 'B'#1#0#0'ë' or value of a different var
end;
finally
PropEditor.free;
end;
end;
Other Details:
- Delphi 2007, Windows 7 64 bit, but can reproduce when testing EXE on XP
- REMOVING CONST STOPS PROBLEM FROM EXHIBITING (but presumably the problem is thus just lurking)
- PropEditor.PromptForXYZPropertiesSettings creates and shows a form. If I disable the ShowModal call then the memory is not trashed. Even though i have REMOVED ALL CONTROLS AND CODE from the form
So I would like some advice on how to debug the issue. I was thinking perhaps watching the memory pointer where the sFilename var exists to see where it gets trashed, but not sure how i would do that (obviously needs to be done within the app so is owned memory).
Thanks