?
Solved

Changing ListView's Columns.Caption property at runtime

Posted on 2003-02-26
7
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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