Microtip #4 const ARGs: array... Application

Source: Internet
Author: User
Microtip #4 const ARGs: Application of array...

// Test in DELPHI6 up2
// Wrtten by skyjacker 2007.03.21
// QQ discuss group: 130970

// Note: The Source Code released by me is for reference only and there is no bug.
// You are welcome to discuss code or bugs.

Application requirements: Use a function to add a row of data to tlistview.
Feature: the number of columns is not fixed.

Therefore, using the open array parameter const ARGs: array of is a good method.
Const ARGs: array of has two forms: fixed type and variable type.

The following two functions are implemented:
Procedure listaddline (const ARGs: array of string; alistview: tlistview );
{* Add a row to the list}
Procedure listaddlinet (const ARGs: array of const; alistview: tlistview );
{* Add a row to the list, multi-type edition}

Usage:
Listaddcolumn ('test 1', lvdata );
Listaddcolumn ('test 2', lvdata );
Listaddcolumn ('test 3', lvdata );

Listaddline ([], lvdata );
Listaddline (['1'], lvdata );
Listaddline (['1', '2'], lvdata );
Listaddline (['1', '2', '3'], lvdata );

Listaddlinet ([], lvdata );
Listaddlinet (['2'], lvdata );
Listaddlinet (['2', 22.2], lvdata );
Listaddlinet (['2', 33, 3.01], lvdata );

Source:

// Add a column header to the list
Procedure listaddcolumn (const acolumncpation: string; alistview: tlistview );
Begin
If assigned (alistview) then
Alistview. Columns. Add. Caption: = acolumncpation;
End;

// Add a row to the list
Procedure listaddline (const ARGs: array of string; alistview: tlistview );
VaR
I: integer;
Begin
If high (ARGs) <0 then
Exit;
With alistview. Items. Add do
Begin
Caption: = ARGs [0];
For I: = low (ARGs) + 1 to high (ARGs) Do
Begin
Subitems. Add (ARGs [I]);
End;
End;
End;

// Add a row to the list, multi-type edition
Procedure listaddlinet (const ARGs: array of const; alistview: tlistview );
VaR
I: integer;
S: string;
Begin
With alistview. Items. Add do
Begin
For I: = low (ARGs) to high (ARGs) Do
Begin
Case ARGs [I]. vtype
Vtinteger:
S: = inttostr (ARGs [I]. vinteger );
Vtboolean:
If ARGs [I]. vboolean then
S: = '1'
Else
S: = '0 ';
Vtchar:
S: = ARGs [I]. vchar;
Vtextended:
S: = floattostr (ARGs [I]. vextended ^ );
Vtstring, vtansistring:
S: = ARGs [I]. vstring ^;
Vtwidechar:
S: = ARGs [I]. vwidechar;
Else
S: = 'unknown type ';
End;
If I = 0 then
Caption: = s
Else
Subitems. Add (s );
End;
End;
End;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.