如题:
  我在form1里面有一个 panel ,form2 里面有一个index 我想当form2 .index =1 的时候
  form1.panel.left -10 现在我可以获取到index 在index =1 的时候 form1.panel.left -10 这个代码也执行了 但是位置没有变化 请问这个要怎么做啊 

解决方案 »

  1.   

    把Index作为Form2的属性来操作
    Form1
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        pnl1: TPanel;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    uses
    Unit2;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Form2.Show;
    end;end.
    Form2
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
        edt1: TEdit;
        Button1: TButton;
        Edit1: TEdit;
        lbl1: TLabel;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        Findex: Integer;       //储存Index
        function GetIndex: Integer;
        procedure setIndex(i: Integer);
      public
        { Public declarations }
        property index: Integer read GetIndex write setIndex;
      end;var
      form2: TForm2;implementation{$R *.dfm}uses
      Unit1;procedure TForm2.setIndex(i: Integer);
    begin
      if i > 0 then
      begin
        Findex := i;
        if Findex = 1 then
          Form1.pnl1.Left := Form1.pnl1.Left - 10;
      end;end;procedure TForm2.Button1Click(Sender: TObject);
    begin
         index:=StrToIntdef(Edit1.Text,0);
    end;function TForm2.GetIndex: Integer;
    begin
      Result := Findex;
    end;end.
      

  2.   

     你好  你的代码确实可以实现功能但是我这边程序的情况有点不一样 不知道是不是这样导致功能不能实现 我是从JS调用的delphi这个函数