如何将数据库"表"转化成"类"的形式(应用比较广泛)(50分)

  • 主题发起人 主题发起人 jack011
  • 开始时间 开始时间
J

jack011

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把数据里的表数据在程序启动时,加载到类里,如何作到调用类和调用表一样方便:<br><br>Student:<br><br>&nbsp; &nbsp; ID &nbsp; &nbsp; &nbsp;Name &nbsp; &nbsp; &nbsp;Sex &nbsp; &nbsp; &nbsp; Age<br>&nbsp; &nbsp; 001 &nbsp; &nbsp; 张三 &nbsp; &nbsp; &nbsp; 男 &nbsp; &nbsp; &nbsp; &nbsp;19<br>&nbsp; &nbsp; 002 &nbsp; &nbsp; 李四 &nbsp; &nbsp; &nbsp; 男 &nbsp; &nbsp; &nbsp; &nbsp;20<br>&nbsp; &nbsp; 003 &nbsp; &nbsp; 小花 &nbsp; &nbsp; &nbsp; 女 &nbsp; &nbsp; &nbsp; &nbsp;19<br>&nbsp; &nbsp; ... &nbsp; &nbsp; .... &nbsp; &nbsp; &nbsp; .. &nbsp; &nbsp; &nbsp; &nbsp;..<br>&nbsp; &nbsp; ... &nbsp; &nbsp; .... &nbsp; &nbsp; &nbsp; .. &nbsp; &nbsp; &nbsp; &nbsp;..<br>&nbsp; &nbsp; ... &nbsp; &nbsp; .... &nbsp; &nbsp; &nbsp; .. &nbsp; &nbsp; &nbsp; &nbsp;..<br><br>Type<br>&nbsp; Class=TStudent<br>&nbsp; &nbsp; ID:sring;<br>&nbsp; &nbsp; Name:string;<br>&nbsp; &nbsp; Sex:char;<br>&nbsp; &nbsp; Age:integer;<br>...............<br><br>...............<br><br>...............<br><br>end;<br><br>如何定义这个类,让调用和表一样简单方便?
 
定义一个数组不就行了 array of TStudent 然后setlength(array,table.recordcount)<br>for i := 0 to recordcount - 1 do<br>&nbsp; array.ID := FieldByName('ID').asstring;<br>&nbsp; ....<br>end;
 
你说的应该是“持久层”,<br>建议你搜一下“鲁棒的持久层”。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
937
SUNSTONE的Delphi笔记
S
后退
顶部