Jump to content

Mike Torrettinni

Members
  • Content Count

    78
  • Joined

  • Last visited

Community Reputation

2 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Mike Torrettinni

    How to get data from class to TVirtualStringTree?

    And this doesn't annoy you, that you can't just double click event and see the code (the RAD thing)? 🙂
  2. Mike Torrettinni

    How to get data from class to TVirtualStringTree?

    Thank you! I think I got it now. I will have a class that connects control and data, so I can attach any VST control to it, or connect any data to the control. This way will avoid cluttering the Main from with all the code. So, when you use your control on the form, you don't have any code in the control events, right? All is defined in this interface, so if you want to see how what OnGetText contains, you have to open the unit with this interface, right?
  3. Mike Torrettinni

    How to get data from class to TVirtualStringTree?

    @joachimd Interesting, own control would be good with all the bells and whistles, instead of constantly applying same changes to new controls... would you mind sharing OnGetText/GetText method details? do you pull full rows or column item one by one from from, or have access to full data structure?
  4. Mike Torrettinni

    How to get data from class to TVirtualStringTree?

    I'm looking for some advice how to connect controls and class, specifically at this moment is Virtual Treeview (TVirtualStringTree - VST). I have a class TABCFileParser that parses text files and holds all the data. I have a method that returns Strings when I want to display some data in TMemo. All good, simple. Now I need to connect the data with VST, and I will use probably a lot of methods (OnGetText, OnGetIconImage, OnPaintText... ). Most of them will be based on data from TABCFileParser class. Up until now, I had no problem because all data was in global variables ( no classes), I just accessed them in each VST method directly. Works good, but once you have a lot of VTSs in Main Form, it gets cluttered with all the code. Then I 'evolved' this into enclosing data into a unit (not a class, yet) and 'exposed' all needed methods like: DataGetText, DataGetIcon... and in VST's methods I call these methods, so the VST's OnGetText has a single line, a call to this DataGetText. This is better, since Main Form unit doesn't get cluttered and I can keep all Data related methods in 1 unit. I was warned not to mix UI elements with data classes. So my idea to just expose ABCGetText, ABCPaintText.. and call them in VST's OnGetText with FABCFileParser.ABCGetText().. is not OK. So, what would be sensible approach to get data from class to VST? I was thinking of a 'bridge' class that would pair up TABCFileParser and VST by pulling data from the ABC class and assign methods to VST. Any other suggestions? Thanks, I appreciate any kind of suggestion!
  5. Mike Torrettinni

    How to switch condition position?

    Thank you for the example! I'm not really new to Delphi, but never grew out of the beginners's level of thinking, I guess... you can find a thread here me questioning about why should I use classes at all 🙂
  6. Mike Torrettinni

    How to switch condition position?

    While I appreciate all the engagement in this thread, the whole question was just a simple 'is it possible' idea. A little more explanation when I got this idea (please consider my beginners level of Delphi experience): So, I have a function that returns default value of a property and since I was just building up this feature, I wanted to know what the defaults are right away. So, this is rough example: if MatchStr('PropertyName', ['Prop1', 'Prop2', 'Prop3', 'Prop4', 'Prop5', 'Prop6', 'Prop7', 'Prop8', 'Prop9', 'Prop10' ]) then Result := 'N' else if (MatchStr('PropertyName', ['PropertyA', 'PropertyB', 'PropertyC', 'PropertyD', 'PropertyE', 'PropertyF', 'PropertyG', 'PropertyH' 'PropertyI', 'PropertyJ', 'PropertyK', 'PropertyL', 'PropertyM', 'PropertyN', 'PropertyO', 'PropertyP', 'PropertyQ'...]) then Result := 'DefaultABC' else if PropertyName = 'CustomProp' Result := 'X' ... and since I was adding new property names and value, I always wanted to know exactly what is already there and what the names and values are, and a Result was an important information, so I was thinking it would be so cool to have it reversed: Result := 'N' if MatchStr('PropertyName', ['Prop1', 'Prop2', 'Prop3', 'Prop4', 'Prop5', 'Prop6', 'Prop7', 'Prop8', 'Prop9', 'Prop10' ]) else Result := 'DefaultABC' if MatchStr('PropertyName', ['PropertyA', 'PropertyB', 'PropertyC', 'PropertyD', 'PropertyE', 'PropertyF', 'PropertyG', 'PropertyH' 'PropertyI', 'PropertyJ', 'PropertyK', 'PropertyL', 'PropertyM', 'PropertyN', 'PropertyO', 'PropertyP', 'PropertyQ'...]) else Result := 'X' if (PropertyName = 'CustomProp') .... So, it's more visual thing, where I first see possible default values and then which property names resolve to it. I know I can do this 10s of other way with lookup table, consts... but this all means the default values and property names are not together, and I would need to jump back and forth to get the right information.
  7. Mike Torrettinni

    How to switch condition position?

    IfThen's are awesome, I use them a lot, but it's not usable for this case, I need Result to be very clear at the beginning.
  8. Mike Torrettinni

    How to switch condition position?

    Thank you, but was trying to avoid using methods, it kind of defeats the purpose of simple If statement.
  9. Mike Torrettinni

    How to switch condition position?

    Yes, no matter what i tried, it didn't compile. Was hoping there is simple solution, missing from help. No luck.
  10. Mike Torrettinni

    How to switch condition position?

    Thanks. I just had an idea if this is possible for one of my statement, where it's a long condition and wanted to reverse so I can see result first.
  11. Mike Torrettinni

    How to switch condition position?

    Well, I can't see anything helpful for my case. I'm looking here: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Declarations_and_Statements_(Delphi)
  12. Mike Torrettinni

    How to switch condition position?

    I didn't provide good example, I'm trying to work on statement like this, working on strings: if Property = 'A' then Result := 'N'; so looking for in idea how to have something like this: Result := 'N' if/when (Property = 'A');
  13. Is it possible to switch the condition to the end: from this: If (condition) Then Result := True; into something like this: Result := True if (condition); Or similar variation, where result is shown first. I know that Case works like that, but I need it to work on string values. When visually looking at the statement, sometimes the Result value has a 'priority' over condition - my personal preference.
  14. OK, thanks for all the time and effort helping me!
  15. It's the little things that count, like a little praise I did good 🙂 Thank you! I made changes and added new Create ctor: constructor Create(Level: integer; const Parent, NodeName: string; const Arguments: TArray<TNodeArgument>); overload; I also changed private to strict private in TABCStructureNode, since the other class was able to access all fields directly instead of properties - the Code completion was confusing by allowing me access to FNodeLevel instead of just NodeLevel property: I also added AddNnode overload that calls new ctor, can you confirm this is OK - to use TABCStructureNode.Create in: procedure TABCFileParser.AddNode(Level: integer; const Parent, NodeName: string; const Arguments: TArray<TNodeArgument>); begin FABCStructure := FABCStructure + [TABCStructureNode.Create(Level, Parent, NodeName, Arguments)]; end; As for the TArray vs TList... I just like TArray, as I'm used to it. unit uParseABCFile2; interface uses System.Classes, Vcl.StdCtrls, Vcl.Dialogs; type TNodeArgument = record ArgName : string; ArgValue : string; end; // File structure basic block TABCStructureNode = class strict private FNodeLevel : Integer; FNodeParent : string; FNodeName : string; FArguments : TArray<TNodeArgument>; strict private function GetArgument(Index: integer): TNodeArgument; function GetArgumentCount: integer; function GetArgumentAsString(Index: Integer): string; public constructor Create; overload; constructor Create(Level: integer; const Parent, NodeName: string; const Arguments: TArray<TNodeArgument>); overload; property NodeLevel: integer read FNodeLevel write FNodeLevel; property NodeParent: string read FNodeParent write FNodeParent; property NodeName: string read FNodeName write FNodeName; // Arguments property ArgumentCount: integer read GetArgumentCount; property Arguments[Index: Integer]: TNodeArgument read GetArgument; procedure AddArgument(Argument: TNodeArgument); procedure DeleteArgument(Index: Integer); property ArgumentAsString[Index: Integer]: string read GetArgumentAsString; // ... end; TABCFileParser = class private FABCFileName: string; // File structure FABCStructure: TArray<TABCStructureNode>; public constructor Create; property ABCFileName: string read FABCFileName write FABCFileName; procedure ParseFile; // File structure procedure AddNode(NodeItem: TABCStructureNode); overload; procedure AddNode(Level: integer; const Parent, NodeName: string; const Arguments: TArray<TNodeArgument>); overload; // CORRECT METHOD FOR UI INTERFACE function GetStructureAsString: string; // Methods for non-UI mode procedure ABCStructureToFile(const aFileName: string); end; implementation { TABCStructure } constructor TABCStructureNode.Create; begin // ??? end; constructor TABCStructureNode.Create(Level: integer; const Parent, NodeName: string; const Arguments: TArray<TNodeArgument>); begin FNodeLevel := Level; FNodeParent := Parent; FNodeName := NodeName; FArguments := Arguments; end; function TABCStructureNode.GetArgument(Index: integer): TNodeArgument; begin Result := FArguments[Index]; end; procedure TABCStructureNode.AddArgument(Argument: TNodeArgument); begin FArguments := FArguments + [Argument]; end; procedure TABCStructureNode.DeleteArgument(Index: Integer); begin Delete(FArguments, Index, 1); end; function TABCStructureNode.GetArgumentCount: integer; begin Result := Length(FArguments); end; function TABCStructureNode.GetArgumentAsString(Index: Integer): string; begin Result := FArguments[Index].ArgName + ' = ' + FArguments[Index].ArgValue; end; { TABCFileParser } constructor TABCFileParser.Create; begin // add something, if needed in the future end; procedure TABCFileParser.ParseFile; var vNewItem : TABCStructureNode; vNewArgument1, vNewArgument2: TNodeArgument; vArguments1, vArguments2: TArray<TNodeArgument>; begin // Parse/Read ABC File - FABCFileName // demo data vNewArgument1.ArgName := 'Arg1'; vNewArgument1.ArgValue := 'Value1'; vNewArgument2.ArgName := 'Arg2'; vNewArgument2.ArgValue := 'Value2'; vArguments1 := TArray<TNodeArgument>.Create(vNewArgument1, vNewArgument2); vNewArgument1.ArgName := 'Arg3'; vNewArgument1.ArgValue := 'Value3'; vNewArgument2.ArgName := 'Arg4'; vNewArgument2.ArgValue := 'Value4'; vArguments2 := TArray<TNodeArgument>.Create(vNewArgument1, vNewArgument2); AddNode(0, 'Parent', 'ABC Node 1', vArguments1); AddNode(1, 'ABC Node 1', 'ABC Node 2', vArguments2); end; procedure TABCFileParser.AddNode(NodeItem: TABCStructureNode); begin FABCStructure := FABCStructure + [NodeItem]; end; procedure TABCFileParser.AddNode(Level: integer; const Parent, NodeName: string; const Arguments: TArray<TNodeArgument>); begin FABCStructure := FABCStructure + [TABCStructureNode.Create(Level, Parent, NodeName, Arguments)]; end; procedure TABCFileParser.ABCStructureToFile(const aFileName: string); begin // Save ABC Structure to File // ... end; function TABCFileParser.GetStructureAsString: string; var i,j: Integer; begin Result := ''; for i := Low(FABCStructure) to High(FABCStructure) do begin Result := Result + FABCStructure[i].NodeName; Result := Result + ' Arguments: '; for j := 0 to FABCStructure[i].ArgumentCount - 1 do Result := Result + FABCStructure[i].ArgumentAsString[j] + '; '; Result := Result + sLineBreak; end; end; end.
×