How to make this simple...

I have some code that works, but 1 its annoying to add new stuff. 2 its really repeating..

Pretty much I have some boxes on the screen and when you click on one, it will open a new form and put data from the database to the form, Telling you which machine numbers are in this area / square.. The code is not long but repeats alot.. anyhow i attached a copy..

http://www11.zippyshare.com/v/32620272/file.html


but here you can see a sample of what i mean
procedure TForm1.Shape10MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  getdata('Mod7','Dept: 721');
end;

procedure TForm1.Shape11MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  getdata('Mod9','Dept: 721');
end;

procedure TForm1.Shape12MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  getdata('AOI14','Dept: 721');
end;

Comments

  • I think I would write a new component to replace the TShape & TLabel combination you have now. Either base it on TShape and add a caption or it would be very easy to just base it on a TPanel.
    Add Location and department published properties to your new component so you can set the 'Mod9' and 'Dept: 721' as properties in the object inspector.
    Add a Published Query property so you can link the new components to your existing query just by setting a property in the object inspector.
    Add a method to handle the WM_LButtonDown message and get the data when you receive that message. You could parameterize the data retrieval so you don't need to repeat the code for that for mechanical & electrical.
    When you retrieve the data from the database use it to populate a TStrings property.
    Finally add an onDataChange event to your new component and fire that event after getting the data from the database.
    All instances of your new component could then share a single onDataChange event handler which would just be something like
    TForm1.MachineDataChange(Sender : TObject);
    begin
      Form2.Memo1.Lines.AddStrings(TMyNewComponent(Sender).Data);
    end;
    
    This would replace all the event handlers you have at the moment. The data retrieval code would be encapsulated within your new component and not seen from your front end form unit.
  • Thanks, did this just about exactly! working good and alot easier to edit..
    Cheers
    Glen


    GAME TIME!!!
Sign In or Register to comment.