FiftyTifty
Members-
Content Count
4 -
Joined
-
Last visited
Everything posted by FiftyTifty
-
Got a rather odd issue. The code completion options, such as auto parenthesis, do not work at all. The only thing that works, is the code history suggestion if I set Delphi Rad Studio to use the classic code insight. Nothing else works. Here's a screenshot of my IDE settings: https://i.imgur.com/vzGogyH.png I'm a bit spoiled by Visual Code, as I use it for making Lua scripts for Total War. The auto brackets, the auto indenting, and the auto string quotes save so much faffing about. Any idea how to fix this?
-
TStringList property in custom class constructor doesn't persist
FiftyTifty posted a topic in General Help
I'm working on programs that make modding Conan Exiles much easier, as the editor is very lacking. The game heavily relies upon databases, and the editor is like a very, very basic spreadsheet. Luckily, it supports importing and exporting JSON data, so I've something to work with. I will say that I'm completely self taught at programming, and had a mentor back when I first started learning how to use Delphi. Now, here is the problem. I've a custom class CEItemStatModification, which has a TStringList property CEItemStatModification.Modifications. The constructor runs and creates the TStringList, but for some reason, I have to call .create; on it again in my actual code, otherwise it's invalid and doesn't return anything. Maybe it's getting destroyed for some reason? Here's the repository, with libraries being up one folder: https://github.com/FiftyTifty/Conan-Exiles/tree/master/Conan Exiles - ItemStatModification Editor Here's the JSON data: https://pastebin.com/Zei7W190 Here's the custom class code: https://github.com/FiftyTifty/Conan-Exiles/blob/master/Conan Exiles - API/fytyConanExilesTypes.pas Specifically, here it is along with the constructor: CEItemStatModification = class public [JsonName('RowName')] RowName : string; [JsonName('Modifications')] Modifications : TStringList; published constructor Create; destructor Destroy; end; ptrCEItemStatModification = ^CEItemStatModification; implementation constructor CEItemStatModification.Create; begin //ShowMessage('Created TStringList!'); Modifications := TStringList.Create; end; destructor CEItemStatModification.Destroy; begin ShowMessage('Destroyed object!'); Modifications.Free; end; end. That ShowMessage() line prints properly with each object created in my main code. But it doesn't persist. If I don't call TStringList.Create again in my code, no string data will be returned: procedure TformWindow.buttonLoadClick(Sender: TObject); var ... begin ... for djsonEntry in djsonDataTable do begin //ShowMessage('Iteration number: '+ iCounter.ToString); ceismToAdd := CEItemStatModification.Create; ceismToAdd.Modifications := TStringList.Create; //ShowMessage('Created CEItemStatModification!'); for djsonISMod in djsonEntry['Modifications'] do begin //ShowMessage(djsonISMod.AsString); ceismToAdd.Modifications.Add(djsonISMod.AsString); end; ... But that brings a new problem. Every created object will have the exact same TStringList data as the first created object. And I can't figure out why. Any ideas? -
TStringList property in custom class constructor doesn't persist
FiftyTifty replied to FiftyTifty's topic in General Help
I actually found the problem when I was going to uncomment my ShowMessage() lines. See this wee block? ShowMessage(IntToStr(listCEItemStatModification.Add(ceismToAdd))); ShowMessage('Added ItemStatModification to master list! ' + ceismToAdd.RowName); ShowMessage(IntToStr(iCounter)); treeEntry := formTree.Items.AddChildObject(nil, djsonEntry['RowName'].AsString, listCEItemStatModification.Items[iCounter]); //ShowMessage('Added tree node!'); if tstrlistItemIDs.IndexOf(treeEntry.Text) >= 0 then treeEntry.Text := treeEntry.Text + ' - ' + tstrlistItemNames[(tstrlistItemIDs.IndexOf(treeEntry.Text))]; else //ShowMessage(treeEntry.text); Inc(iCounter); Forgot to comment the else statement. In my defence, I've been doing my coding at 2am. -
TStringList property in custom class constructor doesn't persist
FiftyTifty replied to FiftyTifty's topic in General Help
My apologies, I'll clarify. If I don't call TStringList.Create again in my code, no string data will be returned. As in, the TStringList property .Modifications of my class will return completely blank strings. So for some reason, the TStringList that is created in my class' constructor isn't persisting for some reason. So here's the JSON situation. Conan Exiles' devkit allows exporting the databases as JSON text. So I made a memo that you paste the JSON into, and using the Delphi-JSON library, I read the data inside each JSON object into another object of my class. Here's the code without the commented out ShowMessage() lines: procedure TformWindow.buttonLoadClick(Sender: TObject); var iCounter, iNumModifications, iCounterModifications, iAddedIndex: integer; treeEntry: TTreeNode; ceismToAdd: CEItemStatModification; djsonEntry, djsonISMod: TDJSON; begin djsonDataTable := TdJSON.Parse(formWindow.formSource.Lines.Text); iCounter := 0; if listCEItemStatModification.Count > 0 then listCEItemStatModification.Clear; for djsonEntry in djsonDataTable do begin ceismToAdd := CEItemStatModification.Create; ceismToAdd.Modifications := TStringList.Create; for djsonISMod in djsonEntry['Modifications'] do begin ceismToAdd.Modifications.Add(djsonISMod.AsString); end; ceismToAdd.RowName := djsonEntry['RowName'].AsString; listCEItemStatModification.Add(ceismToAdd); treeEntry := formTree.Items.AddChildObject(nil, djsonEntry['RowName'].AsString, listCEItemStatModification.Items[iCounter]); if tstrlistItemIDs.IndexOf(treeEntry.Text) >= 0 then treeEntry.Text := treeEntry.Text + ' - ' + tstrlistItemNames[(tstrlistItemIDs.IndexOf(treeEntry.Text))] else Inc(iCounter); end; Then once the data has been modified, the user will just need to press the save button, and my objects will be output into the bottom memo as JSON data. Ctrl+A -> Ctrl+C -> Open Devkit -> Ctrl+V. Easy. Don't know a thing about breakpoints, but I essentially did the exact same thing but with ShowMessage() outputting the data after every line. The JSON data is read from the memo fine. The JSON data is read into the class fine. What fails, is when the objects are added to the TList listCEItemStatModification, they all have the exact same data in their .Modifications property as the very first object added to the TList.