editnew[j]:=tedit.Create(self);
       with  editnew[j] do
       begin
           parent:=morecreatandfree;
           Width:=150;
           Text:='';
           Left:=checknew[j].left+50;
           OnKeyPress:=tquestion.enter;____ERROR
 end;
这段代码你是否写在TQuestion类中
如果是改为:OnKeyPress:=enter;
如果不是那么需要有个QuestionObj:TQuestion
然后OnKeyPress:=QuestionObj.Enter;

解决方案 »

  1.   

    TQuestion不是你的窗体名吧,加上前缀好了。procedure TForm1.Button1Click(Sender: TObject);
    var E : TEdit;
    begin
      E := TEdit.Create(self);
      E.Parent := self;
      E.OnKeyPress := form1.AKeyPress; //这里;
    end;procedure TForm1.AKeyPress(Sender: TObject; var Key: Char);
    begin
      if key = #13 then
        showmessage('fddd');
    end;
      

  2.   

    不行啊,,我是不是写错了
    procedure Tmorecreatandfree.morecreatandfreeactive(Sender: TObject);
    var
        j:integer;
        QuestionObj:tquestion;
    begin
        with  mydatanew.Tnewtiku do
        begin
            open;
            last;
            partmid:=FieldByName('tmid').Value+1;
            append;
            edit;
        end;    i:=strtoint(question.Edit11.text);
        for j:=1 to i do
        begin       checknew[j]:=tcheckbox.Create(self);
           with  checknew[j] do
           begin
               Parent:=morecreatandfree;
               left:=40;
               Caption:='  '+chr(64+j);
           end;       editnew[j]:=tedit.Create(self);
           with  editnew[j] do
           begin
               parent:=morecreatandfree;
               Width:=150;
               Text:='';
               Left:=checknew[j].left+50;
               OnKeyPress:=QuestionObj.enterkeypress;        end;[Warning] moreabcd.pas(68): Variable 'QuestionObj' might not have been initialized
      

  3.   

    我晕!
    你的tquestion显然是一个类
    那么你要有这个类的实例,才能把方法指定出去!
    QuestionObj:=Tquestion.Create是肯定要有的!!!我不知道 你的TQuestion是个什么类,正如yansea(思宏) 所说的
    如果是个Form,则一般会有一个Form类实例,例如:
    TForm1=class(TForm)end;Form1:TForm1;
    (这里Form1是由系统隐含调用了Form1:=TForm1.create的)
    这样,就可以指定  
      OnKeyPress:=Form1.enterkeypress;
    而不是写成
      OnKeyPress:=TForm1.enterkeypress;You know????????????????