unit ere;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, printers,ComCtrls, Mask, DBCtrlsEh;
const  HrTable ='hrgen';
       imagetable ='aaaa';
       adocon='';Type TEXT = Record
     Fiel: string;
     text: string;
     TX: integer;
     TY: integer;
     TFont: TFont;
     TSize: integer;
end;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    number: TEdit;
    StaticText1: TStaticText;
    StaticText2: TStaticText;

  private
    { Private declarations}
  public
    { Public declarations}
  end;var
  Form1: TForm1;implementation{$R *.dfm}
假设我有上面的TEXT = Record
和Type TPhotoe = Record两个类,
现在我要做的就是把 数据赋值给TEXT = Record上面的数据
如我已经有edit1.text,edit2.text,edit3.text,edit4.text,edit5.text,edit6.text的数据,现在我想请问下应该在那里写,把上面6个数据赋值给TEXT = Record上去
因为刚学,没有写过类,求教

解决方案 »

  1.   

    TEXT这个记录类型名称换一下,因为有一个成员名称也是Text(delphi不区分大小写)其他的,看不懂你的需求。把6个Edit的Text赋给这个record的6个元素?那这个TFont咋办?直接赋?
      

  2.   

    TFont暂时不管它,我要做的是text的
      

  3.   

    你寫的是一個RECORD記錄類型,不是類。這個剛開始就要弄清楚。不然麻煩了Type TEXT = Record 
        Fiel: string; 
        text: string; 
        TX: integer; 
        TY: integer; 
        TFont: TFont; 
        TSize: integer; 
    end; //edit1.text,edit2.text,edit3.text,edit4.text,edit5.text,edit6.text var
       myTest : TEXT ; // TEXT 就是你說的那個類,實際是一個記錄類型
      
        mytest.fie1 := Edit1.text;
       mytest.text := Edit2.text;
       mytest.Tx := StrToInt(Edit3.text);
       mytest.ty := StrToInt(Edit4.text);
      

  4.   

    干嘛用record类型,不用TObject实现方法楼上的都贴了
      

  5.   

    Type TEXT = Record
        Fiel: string;
        text: string;
        TX: integer;
        TY: integer;
        TFont: TFont;
        TSize: integer;
    end; 
    这样声明一个结构体后,最好再声明这个结构体的指针,在下面加上一句:
      PTEXT=^TEXT;
    楼主说把数据赋值给TEXT = Record上面的数据,这句话本身就有错误,TEXT是一个结构,而不是对象.就好像你说要把100赋给integer一样.
       要想赋值,必需声明TEXT的一个对象,还要为这个对象申请内存.一般来说,都是声明一个结构的对象指针.
    var
      p:PTEXT;
    begin
      new(p);//申请内存
      p^.Fiel:=?
      p^.text:=?
      .........
      .......... //用完p后,最好销毁它:Dispose(p);
    end;
     
      

  6.   

    mytest为什么加上这个
    说得详细点可以吗?
      

  7.   


    Type TMyTEXT = Record //改一下名字好点,里面成员有同名的
        Fiel: string; 
        text: string; 
        TX: integer; 
        TY: integer; 
        TFont: TFont; 
        TSize: integer; 
    end; type 
      TForm1 = class(TForm) 
        Button1: TButton; 
        Button2: TButton; 
        number: TEdit; 
        StaticText1: TStaticText; 
        StaticText2: TStaticText; 
    。 
      private 
        { Private declarations} 
      public 
        { Public declarations} 
      end; var 
      Form1: TForm1; 
      MyText:TMyText;   //声明一个全局变量
    implementation {$R *.dfm} 
    procedure TForm1.Button1Click(Sender: TObject);//放个按钮在form上面,点击它自动生成这个
    begin
      MyText.Fiel:=Edit1.text;
      MyText.Text:=Edit2.text;
      。。
    end;
    end.
      

  8.   

    mytest为什么加上这个
    说得详细点可以吗?
    这句话什么意思?
      

  9.   

    mytest 是你定义的结构体的一个变量, 通过对象才能访问你开始定义的结构体内的成员
      

  10.   

    先要清楚record声明的是一个数据类型,不是类
    TEXT = Record 
        Fiel: string; 
        Atext: string; 
        TX: integer; 
        TY: integer; 
        AFont: TFont; 
        ASize: integer; 
    end;
    不能用关键字做为变量 
    声明以后再声明变量
    MyText :TEXT ;赋值 with MyText do
       begin
         Fiel:=‘123’
              ...   end;
      

  11.   

    var
       myText : Text;
    begin
        myText.Fiel := edit1.text; 
        myText.text := edit2.text; 
        myText.TX := edit3.text;
        myText.TY := edit4.text; 
        myText.TFont := edit5.text; 
        myText.TSize := edit6.text; 
    end;
      

  12.   

    record为记录,方法上面都已经有了,注意类型转换