Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Changing ListView's Columns.Caption property at runtime

Posted on 2003-02-26
7
Medium Priority
?
302 Views
Last Modified: 2010-04-04
Hi, I have this source code to read the captions, hints, etc for components inside a form.
The thing is, I can't access and change the caption of any ListView (In report Mode)
(e.g.:   ListView.Columns[1].Caption )

Does anyone know how to do this ?


Here is part of  the source code:


  FOR i := 0 TO Form.ComponentCount - 1 DO

   BEGIN
    m := Form.Components[i];


    PropInfo := GetPropInfo(m, 'caption');
    IF PropInfo <> nil THEN
     BEGIN
      acap := GetStrProp(m, PropInfo);
      acap := stringreplace(acap, cr, '~~', [rfreplaceall]);
      IF ((acap <> '') and (acap <> '-')) THEN
        Langini.WriteString('Translations', AForm.Name + '.' + m.Name + '.Caption',
          acap)
     END;

    PropInfo := GetPropInfo(m, 'hint');
    IF PropInfo <> nil THEN
     BEGIN
      ahint := GetStrProp(m, PropInfo);
      ahint := stringreplace(ahint, cr, '~~', [rfreplaceall]);
      IF ahint <> '' THEN
        Langini.WriteString('Translations', AForm.Name + '.' + m.Name + '.Hint', ahint)
     END;

    PropInfo := GetPropInfo(m, 'text');
    IF PropInfo <> nil THEN
     BEGIN
      atext := GetStrProp(m, PropInfo);
      atext := stringreplace(atext, cr, '~~', [rfreplaceall]);
      IF atext <> '' THEN
        Langini.WriteString('Translations', AForm.Name + '.' + m.Name + '.Text', atext)
     END;
  END;

0
Comment
Question by:armasilva
7 Comments
 
LVL 2

Expert Comment

by:BorlandMan
ID: 8030585

Yes, there is no property in the TListView called 'Caption', so the above code will not work.

you could add to this a check to see if it's an object of type TListView

var
  lvw: TListView
  i : integer;
  colName: string;
begin

for i := 0 TO Form.ComponentCount - 1 do
begin
  m := Form.Components[i];

  if m is TListView then
  begin
    lvw := m as TListView;

    for i := 0 to ListView1.Columns.Count-1 do
    begin
      colName := Listview1.Columns.Items[i].Caption;
      // do something with column name here.
    end;
  end
  else
  begin
    // your other way of handling thing with
    // RTTI here
  end;

hth,
J

0
 

Expert Comment

by:GummiStori
ID: 8032830
Hi,

Be sure that you have already made some columns
you can't make a caption to a column that does not exist...

here is a small code:

//First you create Columns
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListView1.Columns.Add;
  ListView1.Columns.Add;

end;

//Then add a caption to them
procedure TForm1.Button2Click(Sender: TObject);
begin
  ListView1.Column[0].Caption := 'hello';
end;

//And Values..
procedure TForm1.Button3Click(Sender: TObject);
var
  li: TListItem;
begin


  li := ListView1.Items.Add;

  li.Caption := 'yea yeah..';
  li.SubItems.Add('all right');

  li.Update;
end;


regards
Gummi St.
0
 

Author Comment

by:armasilva
ID: 8035102
I know that way already, I forgot to mention this in
my previous msg, sorry. But since this will be part
of a freeware component, and there is a lot of ListViews
made, the way you do it, it needs that name, class of
the ListView, and the way in my previous msg will be
more generic, since each user might have different
third parties VCL's (such as dfsExtListView).

I don't want to update the vcl every time a new
Listview is out there ;)

Anyone know a way to get to this subproperties ?

Thanks !
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:CleanupPing
ID: 9317055
armasilva:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 10

Expert Comment

by:kacor
ID: 9981498
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       PAQ and NOT refund points                                        there are a lot of useful infos
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0
 
LVL 10

Expert Comment

by:kacor
ID: 9981511
may be it would be better to split points between BorlandMan and  GummiStori because they placed important comments to this question. they were known for armasilva but he didn't wrote them in his question.

I leave this recommendation

kacor
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10007378
PAQed, with points refunded (50)

Question not answered, but has useful info.

modulo
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question