(tform(Sender).FindComponent('Pagecontrol1') as TPageControl).ActivePageIndex := (tform(Sender).FindComponent('Pagecontrol1') as TPageControl).ActivePageIndex + 1;
uses Unit1;Form1.PageControl1.ActivePageIndex:=...
Here is a short outline of how I like to see code, so you will see how I like to program.I. Main Program 1. Initialize all a. clear all variables b. set defaults c. read in settings file 2. Clear Screen 3. Display Screen 4. Watch for Keypress a.check keypress 1. verify input type 2. verify valid entry 3. verify additional info base on entry b. move to correct next field based on entry 5. Do totals a. verify all data 6. Print report 7. Save Data to external device 8. Check for new entry or exit 9. Exit
I understand the general idea of keeping the form code on the form but I'm talking about generic key handeling routines that will be the same for multiple forms, why duplicate them and take the chance that I miss a set if I have to change something.
{ TIP: Try to create general functions and procedures as if you plan to use them for different project. Believe me, it really helps to keep your code clean and easy to maintain. }{ You can declare many diffrent functions like this one }procedure MyKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState {if needed, you can add any extra parameters that you need to adjust the procedure execution});begin // place your code here.end;
procedure TMyForm.GeneralKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin MyKeyDown(Sender, Key, Shift);end;
sender is a tobject. tobject is a common base class that mostly all of the controls are derived from. It only has basic properties as compared to the controls you use on the form like a tedit. You can access the "advanced" eleaments of the control by casting (upgrading) the sender to the control with the "as" command.Quote from: wpflum on September 03, 2010, 06:25:16 pm... but the problem is that I'm dealing with forms that might have 20 or 30 tedit controls so I'd have to have a lot of code on the form page to handle it.you can assign all of the tedit key down events to the same function. then all you need is one function. you can sort out which one is the active one by (simple) looking at the sender's tag or you can dig into the sender's as tedit. properties like top,left or parent to make your selection.
... but the problem is that I'm dealing with forms that might have 20 or 30 tedit controls so I'd have to have a lot of code on the form page to handle it.