日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于TobjectList的一点疑问

發(fā)布時(shí)間:2024/4/11 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于TobjectList的一点疑问 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
關(guān)于TobjectList的一點(diǎn)疑問 VCL組件開發(fā)及應(yīng)用
http://www.delphi2007.net/DelphiVCL/html/delphi_20061223112301168.html
我用了一個(gè)TObjectList,我想將自己定義的類對(duì)象加進(jìn)去(包含多個(gè)對(duì)象) ?
? 對(duì)象含有多個(gè)字段(屬性),最后我要將各個(gè)對(duì)象,以某字段的值進(jìn)行排序 ?
? ?
? 下面是程序代碼片段---------- ?
? CoDeskList ? := ? TObjectList.Create; ?
? CoDesKList.OwnsObjects ? := ? false;//這個(gè)地方采用默認(rèn)值還是false ?
? ?
? while ? not ? eof ? do//數(shù)據(jù)庫讀出的記錄 ?
? ? ? ? ? ? ? ? ? begin ?
? ? ? ? ? ? ? ? ? ? ? ? ? SvDesk ? := ? TSvDesk.Create;//自定義對(duì)象 ?
? ? ? ? ? ? ? ? ? ? ? ? ? SvDesk.DCoID:= ? Trim(fieldbyname('servdeskcoid').AsString); ?
? ? ? ? ? ? ? ? ? ? ? ? ? SvDesk.Length ? := ? fieldbyname('inorderqueuecurrlength').AsInteger; ?
? ? ? ? ? ? ? ? ? ? ? ? ? SvDesk.Pri ? := ? fieldbyname('pri').AsInteger; ?
? ? ? ? ? ? ? ? ? ? ? ? ? CoDeskList.Add(SvDesk); ?
? ? ? ? ? ? ? ? ? ? ? ? ? SvDesk.Free;//釋放 ?
? ? ? ? ? ? ? ? ? ? ? ? ? next; ?
? ? ? ? ? ? ? ? ? end; ?
? ?
? ? ? MaxPri ? := ? TSvDesk(CoDeskList.Items[0]).Pri;//TSvDesk強(qiáng)制轉(zhuǎn)換 ? 調(diào)試過,有值 ?
? ? ? ID:= ? TSvDesk(CoDeskList.Items[0]).DcoID;//這里為什么讀不出來呢 ?
? ? ? ? ? ? ? ? ? For ? i:= ? 0 ? TO ? Sum_a ? Do ? //找出服務(wù)臺(tái)的最高優(yōu)先級(jí)值 ?
? ? ? ? ? ? ? ? ? begin ?
? ? ? ? ? ? ? ? ? ? ? ? ? if ? MaxPri ? < ? TSvDesk(CoDeskList.Items[i]).Pri ? then ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MaxPri ? := ? TSvDesk(CoDeskList.Items[i]).Pri; ?
? ? ? ? ? ? ? ? ? end; ?
? 最后 ?
? ? ? ? ? CoDeskList.Clear; ?
? ? ? ? ? CoDeskList.Free; ?
? 還有一個(gè)很嚴(yán)重的問題就是CoDeskList里有兩條記錄,但都是最后一條記錄的值(第一條被覆蓋掉了),為什么呢?????????

type ?
? ? ? TSvDesk ? = ? class ?
? ? ? private ?
? ? ? ? ? FDCoID: ? string; ?
? ? ? ? ? FLength: ? Integer; ?
? ? ? ? ? FPri: ? Integer; ?
? ? ? protected ?
? ? ? public ?
? ? ? ? ? property ? DCoID: ? string ? read ? FDCoID ? write ? FDCoID; ?
? ? ? ? ? property ? Length: ? Integer ? read ? FLength ? write ? FLength; ?
? ? ? ? ? property ? Pri: ? Integer ? read ? FPri ? write ? FPri; ?
? ? ? end; ?
? ?
? ? ? TFormDemo ? = ? class(TForm) ?
? ? ? ? ? ADOQuery: ? TADOQuery; ?
? ? ? ? ? ButtonDemo: ? TButton; ?
? ? ? ? ? procedure ? ButtonDemoClick(Sender: ? TObject); ?
? ? ? private ?
? ? ? ? ? { ? Private ? declarations ? } ?
? ? ? public ?
? ? ? ? ? { ? Public ? declarations ? } ?
? ? ? end; ?
? ?
? var ?
? ? ? FormDemo: ? TFormDemo; ?
? ?
? implementation ?
? ?
? {$R ? *.dfm} ?
? //排序函數(shù)(降序) ?
? function ? ComparePri(Item1, ? Item2: ? TObject): ? Integer; ?
? begin ?
? ? ? if ? TSvDesk(Item1).Pri ? > ? TSvDesk(Item2).Pri ? then ?
? ? ? ? ? Result ? := ? -1; ?
? ? ? if ? TSvDesk(Item1).Pri ? = ? TSvDesk(Item2).Pri ? then ?
? ? ? ? ? Result ? := ? 0; ?
? ? ? if ? TSvDesk(Item1).Pri ? < ? TSvDesk(Item2).Pri ? then ?
? ? ? ? ? Result ? := ? 1; ?
? end; ?
? ?
? procedure ? TFormDemo.ButtonDemoClick(Sender: ? TObject); ?
? var ?
? ? ? CoDeskList: ? TObjectList; ?
? ? ? SvDesk: ? TSvDesk; ?
? ? ? MaxPri: ? Integer; ?
? ? ? ID: ? Integer; ?
? begin ?
? ? ? CoDeskList ? := ? TObjectList.Create; ?
? ? ? //CoDesKList.OwnsObjects ? := ? False; ? //Default ? = ? True ?
? ? ? try ?
? ? ? ? ? with ? ADOQuery ? do ?
? ? ? ? ? begin ?
? ? ? ? ? ? ? while ? not ? Eof ? do//數(shù)據(jù)庫讀出的記錄 ?
? ? ? ? ? ? ? begin ?
? ? ? ? ? ? ? ? ? SvDesk ? := ? TSvDesk.Create;//自定義對(duì)象 ?
? ? ? ? ? ? ? ? ? SvDesk.DCoID:= ? Trim(FieldByName('ServDeskCoID').AsString); ?
? ? ? ? ? ? ? ? ? SvDesk.Length ? := ? FieldByName('InOrderQueueCurrLength').AsInteger; ?
? ? ? ? ? ? ? ? ? SvDesk.Pri ? := ? FieldByName('Pri').AsInteger; ?
? ? ? ? ? ? ? ? ? CoDeskList.Add(SvDesk); ?
? ? ? ? ? ? ? ? ? //SvDesk.Free;//不要釋放 ?
? ? ? ? ? ? ? ? ? Next; ?
? ? ? ? ? ? ? end; ?
? ? ? ? ? end; ?
? ? ? ? ? CoDeskList.Sort(@ComparePri); ?
? ? ? ? ? MaxPri ? := ? TSvDesk(CoDeskList.Items[0]).Pri; ?
? ? ? finally ?
? ? ? ? CoDeskList.Free; ?
? ? ? end; ?
? end;

DELPHI ? HELP ?
? ?
? OwnsObjects: ?
? ?
? Allows ? TObjectList ? to ? free ? objects ? when ? they ? are ? deleted ? from ? the ? list ? or ? the ? list ? is ? destroyed. ?
? ?
? OwnsObjects ? allows ? TObjectList ? to ? control ? the ? memory ? of ? its ? objects. ? If ? OwnsObjects ? is ? true ? (the ? default), ?
? ?
? calling ? Delete ? or ? Remove ? frees ? the ? deleted ? object ? in ? addition ? to ? removing ? it ? from ? the ? list. ?
? calling ? Clear ? frees ? all ? the ? objects ? in ? the ? list ? in ? addition ? to ? emptying ? the ? list. ?
? calling ? the ? destructor ? frees ? all ? the ? objects ? in ? the ? list ? in ? addition ? to ? destroying ? the ? TObjectList ? itself. ?
? assigning ? a ? new ? value ? to ? an ? index ? in ? Items ? frees ? the ? object ? that ? previously ? occupied ? that ? position ? in ? the ? list.

還有一個(gè)很嚴(yán)重的問題就是CoDeskList里有兩條記錄,但都是最后一條記錄的值(第一條被覆蓋掉了),為什么呢????????? ?
? ------------------------------------ ?
? 呵呵。 ? 一切都是指針惹的禍。

總結(jié)

以上是生活随笔為你收集整理的关于TobjectList的一点疑问的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。