For Delphi 10.2.3: Not sure how to ask this question, but how do I create a method similar to memo1.lines.add(); and memo1.Lines.Count.ToString; where lines contains many other methods, procedures, and properties??
This is how I think it maybe:
unit.someproperty.anotherproperty.mymethod(myvariable: variabletype): variabletype;
or
unit.someproperty.unit2.mymethod(myvariable: variabletype): variabletype;
Appearance would appear like:
function component.extract.tagA(attribute, source: string): string;
procedure component.insert.tagA(attribute, source, dest: string);
procedure component.modify.tagA(attribute, source, dest: string);
if you type component. it would give you help with extract, insert, and modify as options to use next.
So, how do i make a function or procedure where I can have .extract. or .extract. or .insert. ETC
I know this should probably be basic knowledge, but the project I'm working on is becoming big enough for me to make it easier to read and use. I know this can be done, but I don't know how to word it properly in order to find what I need to do this.
I want to have multiple units... then I create a component using them so they have nested methods and procedures that work like those DOTTED methods and procedures you see in Tmemo... like memo1.lines.add, memo1.lines.delete, memo1.lines.insert, etc.
Please help! Thanks in advance!
Delphi syntax does not permit you to declare a class to have dotted sub-properties.
However, you can achieve the effect of this by using a style of coding known as fluent design (see https://en.wikipedia.org/wiki/Fluent_interface). Here is an ultra-simple example:
type
TMySubProperty = class
protected
procedure DoSomething;
property Width : Integer read {define getter and setter}
end;
TMyComponent = class(TComponent)
[...]
property
MySubProperty : TMySubProperty read GetMySubProperty;
end;
[...]
function TMyComponent.GetMySubProperty : TMySubProperty;
begin
Result := {calculate the result however you like}
end;
Then, in your code you can write things like
MyComponent.MySubProperty.Width := 666;
MyComponent.MySubProperty.DoSomething;
Obviously you can have any number of sub-properties and they can be nested to any arbitrary
level: basically, you need a class type for the sub-property and a function in the owning
class (TMyComponent in this simple example) which returns the class instance you are trying
to access. The Getter
Functions can be coded to accept parameters which identify a specific
instance of the sub-property class, as in
MyComponent.MySubProperty[i].Width := 666;
That should be enough to get you going, if not ask.