Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

data exchange between component and a Form

Posted on 2004-04-23
18
339 Views
Last Modified: 2010-04-05
Hi,
I wrote my first component:   MyComponent = Class (Tframe) ....;
a) This Component invokes  a  Form called TChildForm;  I can send data to the child form
with a function like ChildForm.SendData(Data: myData); But How to send Back the data
to the component. The Component is placed for debugging reason on a Form called MyParentForm.
Sending Back Data from the ChildForm to the Compenent goes at the moment like this
        MyParentForm.MyComponent.getdata(.....);
How th access the Component directly without using the Parent-Form  ?

b) Can i use property also for the Tframe-Class, just like a for "normal" component ?
regards
BdLM
     
0
Comment
Question by:BdLm
  • 9
  • 9
18 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10900486
Add in your SendData function the variable for the component....
Like

Function SendData(Data: Mydata; var FromComponent: TMyComponent):...... assuming that TMyComponent is the type of your MyComponent

then Use FromComponent.GetData....

And this should be done also for TFrame i guess (don't know about the structure of your senddata and getdata procs)....
0
 
LVL 8

Author Comment

by:BdLm
ID: 10947217
still i get a run time error, i ' ll post more source code soon
0
 
LVL 8

Author Comment

by:BdLm
ID: 10948359
unit Unit_BitMapMidiClient;
{ The mdi-child, just contains the component  and nothing more...}

interface

type
  TMyMDIForm = class(TForm)
    DBitMap  : DClientFrame;

    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormResize(Sender: TObject);


   
  private

  public
    ID   : Integer;

  end;
--------------------------------------------------------------------------
unit SSCImageClientFrame;
{ the component, keeps all controls and the algorithms for bitmap manipulations }


type
  MidiModeOptions = (master,client);

  TDClientFrame = class(TFrame)
    MyPaintBox  : TPaintBox;
    xScrollBar  : TScrollBar;
    .....
  public
    { Public-Deklarationen }
    FrameBitMapData     : TParameterRecord; { a large data record }
    MyPointList         : TList;
    .....
end;

implementation

uses  ...., Unit_ServerParameter;



{******************************************************************************
 *  Edit The Data .....
 ******************************************************************************}
procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');

     ServerParameterForm.Init(FrameBitMapData, MyPointList);

     ServerParameterForm.ShowModal;
end;



--------------------------------------------------------------------------
unit Unit_ServerParameter;
{  the user dialog form, called from the component }

type
  TServerParameterForm = class(TForm)
  ....
  public
    { Public-Deklarationen }
    MyImageParameter     :  TParameterRecord;     { New Values  for Update and Changes }
    UndoImageParameter   :  TParameterRecord;     { If user want to make an Undo command }
    MyPointList          :  TList;
    UndoPointList        :  TList;


   
    procedure Init(ImageParameter  : TDisPlayBitMap; PointList :  TList);
  end;


procedure TServerParameterForm.Init(ImageParameter  : TDisPlayBitMap; PointList :  TList );
var    i   : Integer;
begin

         ....  // send the data to the FORM, called from the component , Works fine

end;


procedure TServerParameterForm.CloseBitBtnClick(Sender: TObject);
begin
      // Copy Back the Edited Data to the Component in the MDI Child

      MyMDIForm.DBitMap.FrameBitMapData := MyImageParameter;  <--  RUN TIME ERROR ???

      Close;
end;


what is the best way to send the data from the form back to the calling component ?
regards
BdLM

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10948546
the runtime error is raised because you're passing the parameters from the component to the ServerParameterForm, but returning values to a component owned by the MDI that is unknowed by the original caller...

BTW as ServerParameterForm is a Modal Dialog Form you can do this:

procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');

     ServerParameterForm.Init(FrameBitMapData, MyPointList);

     ServerParameterForm.ShowModal;
     If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter;//these params must be accessible from TDClientFrame....
            etc...etc...
            ServerParameterForm.Free;
        end;
end;

and in ServerParameterForm.CloseBitBtnClick
ModalResult := mrOK;
end;

try this way and tell about it


0
 
LVL 8

Author Comment

by:BdLm
ID: 10949469
It works only once, recalling this code at a later step creates again an access vialoation
(writing to address .....)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10949732
that could be because the line ServerParameterForm.Free;

As i can see there's not a Creation call into the EditBasicImageDataSet;

If so Add there:

If not Assigned(ServerParameterForm) then
//create the ServerParameterForm
ServerParameterForm.Init(FrameBitMapData, MyPointList);
     ServerParameterForm.ShowModal;
  etc..

or simply remove the above ServerParameterForm.Free;
In this case take care that the Init procedure passes the whole parameters correctly without letting some dirty values in SaveParameterForm from the last access....


0
 
LVL 8

Author Comment

by:BdLm
ID: 10950215
Ok, without ServerParameterForm.Free;
final Question:
If not Assigned(ServerParameterForm) then  
ServerParameterForm:=TServerParameterForm.create ??
0
 
LVL 8

Author Comment

by:BdLm
ID: 10950266
ServerParameterForm:=TServerParameterForm.create(nil) seems to be OK, but i should
exchange nil with the component , correct ?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10950296
@If not Assigned(ServerParameterForm) then  
ServerParameterForm:=TServerParameterForm.create ??


Yes, and it depends on wich must be the owner of the form:

You can create it owned by the application, so
ServerParameterForm:=TServerParameterForm.create(Application)

or simply create it with no Owner

ServerParameterForm:=TServerParameterForm.create(nil); that is the better way for me beacause you don't have to own any subcomponent of this form, but simply creatte it, use it and then destroy....
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10950400
ah, and just to be more correct this
    If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter
            etc...etc...
            ServerParameterForm.Free;
        end;
might be
procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');
     If not Assigned(ServerParameterForm) then  
        ServerParameterForm:=TServerParameterForm.create(nil);
     try
        If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter
            etc...etc...
         end;
     finally
        ServerParameterForm.Free;
     end;
end;
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 200 total points
ID: 10950414
sorry, missed the showmodal call :))

procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');
     If not Assigned(ServerParameterForm) then  
        ServerParameterForm:=TServerParameterForm.create(nil);
     try
        ServerParameterForm.ShowModal;
        If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter
            etc...etc...
         end;
     finally
        ServerParameterForm.Free;
     end;
end;
0
 
LVL 8

Author Comment

by:BdLm
ID: 10987435
Hi,
i made a error and did all test with  \\ ServerParameterForm.Free;
Activating this code line the run time error occurs, even i thing the code above is correct,
why do i get the run time error.
Could you help again ?
BdLm
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10987829
maybe there's something in the ServerParameterForm.OnDestroy that causes the Exception....
0
 
LVL 8

Author Comment

by:BdLm
ID: 10987923
basically empty, i did not implement an OnDestroy procedure
 
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10988037
mmm...remove this part from TDClientFrame.EditBasicImageDataSet;

      If not Assigned(ServerParameterForm) then  
0
 
LVL 8

Author Comment

by:BdLm
ID: 10989799
i found 1 bug, with another more simple subform in my component:



type
  TMDIDataBaseForm = class(TForm)

    procedure Init(MyPointList :  TList);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    PointList       :  TList;

   

  end;

procedure TMDIDataBaseForm.FormCreate(Sender: TObject);
begin
      PointList:=TList.Create;
end;

procedure TMDIDataBaseForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
     //
end;

procedure TMDIDataBaseForm.FormDestroy(Sender: TObject);
begin
      PointList.Free;
      inherited;
end;




procedure TMDIDataBaseForm.Init(MyPointList : TList);
var  i                : Integer;
     APointRecord     : PPointList;
begin

    //*******************   Bug is here ---->>>>>>>>>>>>>>>>>>      
     PointList:= MyPointList;

end;


here must be some invalid operation, but i don't know why ?
May I not send a TList Object from my component to the sub-Form (lets call it child form)?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10994273
as i can see from the above posted you have to assign the pointlist instead to declare it :=

Just PointList.Assign(MyPointList);
0
 
LVL 8

Author Comment

by:BdLm
ID: 11049133
I'm still not happy with the data-exchange between the component and the "Child"-Form.
What you do for http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20985800.html
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question