目的:在MEMO控件中显示结果,该行通过object存放进行下步处理所需数据.
问题:写入正常,但是,取出Tobject里的内容时出错,请问该怎么在这里取出数据?在combobox、treeview、checklistbox、listbox里用得很正常啊,到底错在哪了?请指教。
type
    Pindustry = ^Tindustry;
    Tindustry = record
    indust_code:string;
    end;
....procedure....
var 
 s:string;
 indust:Pindustry;
 begin
   ...
   new(indust);
   indust.indust_code:=s; 
   Memotest.Lines.AddObject('测试字串',Tobject(indust));
   ...
 end;
end;//----------以上为写入,功能正常
showmessage(Pindustry(Memotest.Lines.Objects[0])^.indust_code);//到这里出错,取不出值来。PS:本想给500分的,可寒...最高只能给100:(((

解决方案 »

  1.   

    用StringList吧,  
    StrLst1.AddObject('测试字串',Tobject(indust));
    Memotest.Lines.Assign(StrLst1);
    showmessage(Pindustry(StrList1.Objects[0]).indust_code);
      

  2.   

    测试通过了,但是,有两个问题:
    1、既然memo提供了addobject为什么不能正常使用呢?是我在使用的时候没用对吗?
    2、为什么要通过Tstring这类东西来中转呢?
    3、创建的StrLst1只有在调用完后才能释放,这样一来,感觉是memo中是一个花瓶来显示东西而已,不太爽。还有更好的方法吗?就死用memo提供的东西来做成不成?无论怎么样,还是先谢谢forgetter() 了,还有关注这个话题的朋友。分数不成问题,关键在解决问题还不算,还得弄清为什么。
      

  3.   

    Contains the individual lines of text in the memo control.property Lines: TStrings;DescriptionUse Lines to manipulate text in an memo control on a line-by-line basis. Lines is a TStrings object, so the TStrings methods may be used for Lines to perform manipulations such as counting the lines of text, adding new lines, deleting lines, or replacing lines with new text.To work with all the text at once, use the Text property. To manipulate individual lines of text, the Lines property works better.Note: Although Lines is implemented as a TStrings descendant, it does not implement the support for associating objects with the strings in the list.TStrings 对很多抽象的方法都不实现,要由后代类实现。
    Lines 正是 TStrings 类的,它并没有实现与 Object 有关的操作
      

  4.   

    执行   Memo1.Lines.AddObject('测试字串',Tobject(indust));
    实际调用过程是==>TStrings.AddObject==>TStrings.PutObject TStrings.PutObject(Index: Integer; AObject: TObject); virtual;
    是个虚方法,它里面没有实现.TMemo里面使用的TStrings是TMemoStrings类
    它既没有去实现AddObject也没有去实现PutObject.
    你跟踪一下程序很容易看出来.
    --------------------------------------------------------
    其实代码可以改成这样   i:=Memo1.Lines.Add('测试字串');
       Memo1.Lines.Objects[i]:=Tobject(indust);