FMX StringGrid根據內容自適應列寬

2022-07-12 04:27:12 字數 1171 閱讀 1815

fmx stringgrid根據內容自適應列寬

1

//maxrow,預設只排序前面100行以內的資料2//

maxwidth,預設單字段顯示的最大寬度

3function getcolmaxdatalength(asgrid: tstringgrid;maxrow:integer=100;maxwidth:integer=400

): tobject;

4var

5 maxcollength, //

列資料的最大長度

6 celllength: single; //

單元格長度

7acol,arow: integer;

8l_maxrow:integer;

9begin

10with asgrid do

11begin

12 l_maxrow:=min(maxrow,columncount);

13for acol := 0

to columncount - 1

do14

begin

15 maxcollength:=canvas.textwidth(columns[acol].header);//

取列頭寬度

16for arow := 0

to l_maxrow - 1

do//

為了效率,最大行數預設為100

17begin

18 celllength := canvas.textwidth(cells[acol,arow]);//

取單元格寬度

19if celllength > maxcollength then

20 maxcollength :=celllength;

21end

;22 columns[acol].width := min(maxwidth,maxcollength + 20); //

加上乙個值調整列寬

23end;24

end;

25end;

應用很簡單,一句搞定: 

getcolmaxdatalength(stringgrid1);

linux根據條件查詢檔案 根據檔案內容查詢檔案

find 命令選項 路徑 表示式選項 選項 empty 查詢空白檔案或目錄。group 按組查詢。name 按文件名稱查詢。iname 按文件名稱查詢,且不區分大小寫。mtime 按修改時間查詢。size 按容量大小查詢。user 按使用者查詢。exec 對找到的檔案執行特定的命令。a 並且。o 或...

根據模板生成word

var product list product list賦值 var filename 文件模板.docx var filernd upload temp session.sessionid.tostring parseint math.random 1000000 docx var fso ne...

根據IP獲取省市

public class ipaddress 2 0 4 d 25 0 5 01 d d?ip正則 string ip string.empty ip位址 string country string.empty 國家 string adr string.empty 省市 string html ge...