Assume I have created a new FMX project with nothing more than a TButton and a TProgressBar on it.
Now I added a ‘Countertest.pas’ file using [Shift] + [F11]. (see code below)
Now I have implemented a procedure into ‘Unit1.pas’ (the main app) to be triggered by a procedure inside the ‘Countertest.pas’ file to change the Value of the TProgressBar.
Inside ‘Unit1.pas’ I wrote this to be called from inside the ‘Countertest.pas’ file:
procedure TForm1.SomethingChanged(newPercentage:Integer);
begin
ProgressBar1.Value:=newPercentage;
showmessage(‘Congratulations, you have just reached ‘+IntToStr(newPercentage)+’ Percent ;)’);
end;
To simplify my problem, this is my stripped down ‘Countertest.pas’ file:
unit Countertest;
interface
uses FMX.Memo; // Will be used later
type
TCountertest = Class
private
zahl: Integer;
published
constructor Create();
destructor Destroy();
procedure Counter();
property Percentage: Integer read zahl;
end;
implementation
constructor TCountertest.Create();
begin
end;
destructor TCountertest.Destroy();
begin
end;
procedure TCountertest.Counter();
begin
for i := 0 to 1337 do
Percentage:=0;
begin
zahl:=i;
if Percentage<>round(i / 100) then
begin
// Here I want to call a Procedure inside ‘Unit1.pas’ to change a Value of the TProgressBar (and some other components like TLabel.Text)
end;
Percentage:=round(i / 100);
end;
end;
end.
As far as I know there is the possibility to use something like procedure(Sender: TObject) of object; and it seems to be the thing a want to use, however I don’t have any idea of how to use this.
My Intention is to write something similar to an OnChange Event used in a TEdit Control.
Of Course I could add ‘Unit1.pas’ into the Uses section of ‘Countertest.pas’ and then call the procedure directly, but as have to handle multiple Instances of TCountertest, I want to have it more like this:
procedure InstanceOfTCountertest.SomethingChanged(newPercentage:Integer);
begin
ProgressBar1.Value:=newPercentage;
showmessage(‘Congratulations, you have just reached a new Percent ;)’);
end;
In the final app there are multiple Instances of TCountertest, so I have multiple Progressbars as well (and other GUI components such as TLabels).
Maybe there are other ways to do this, so feel free to suggest anything, that could fit the purpose to show the Progress of those Instances.