Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Label with Lines Property

Posted on 2004-04-04
5
Medium Priority
?
232 Views
Last Modified: 2012-05-04
Anyone know where I can get a label component that has a Lines property ? (ie. ability to load text from a file or have text longer then 256 characters.) Already looked at torrys but nothing there.

Plz do not suggest a memo or richedit control unless you know of one that has an autosize property and hides the selection box and caret which pretty much will leave you with a (drumroll please) label with a lines property :)
0
Comment
Question by:ezpete
[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
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 100 total points
ID: 10754583
unit MultilineLabel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TMultilineLabel = class(TLabel)
  private
    FLines: TStrings;
    function GetLines: TStrings;
    procedure SetLines(Value: TStrings);
  protected
  public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Lines: TStrings read GetLines write SetLines;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Tests', [TMultilineLabel]);
end;

constructor TMultilineLabel.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  FLines := TStringList.Create;
end;

destructor TMultilineLabel.Destroy;
begin
  FLines.Free;
  inherited;
end;

function TMultilineLabel.GetLines: TStrings;
begin
  Result := FLines;
  Result.Text := Caption;
end;

procedure TMultilineLabel.SetLines(Value: TStrings);
var
  i                 : Integer;
begin
  FLines.Assign(Value);
  Caption := '';
  for i := 0 to FLines.Count - 1 do
  begin
    Caption := Caption + FLines[i];
    if (i < FLines.Count - 1) then
      Caption := Caption + #13#10;
  end;
end;

end.


Shane
0
 

Author Comment

by:ezpete
ID: 10754789
Thx but it seems LoadFromFiles does not work

tried

MultilineLabel1.Lines.LoadFromFile('readme.txt');

and nothing happens.
0
 
LVL 11

Assisted Solution

by:ZhaawZ
ZhaawZ earned 100 total points
ID: 10754855
It's not difficult to read the file.

var
  f : file;
  s : string;
begin
AssignFile(f,'readme.txt');
FileMode := fmOpenRead;
Reset(f,1);
SetLength(s,filesize(f));
BlockRead(f,s[1],length(s));
CloseFile(f);
MultilineLabel1.Caption := s;
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 10754876
If only difference from standart TLabel is possibility to load text from file - there is no need to use another component. There also is no need to use TStrings, which has many needless functions in this case.
0
 

Author Comment

by:ezpete
ID: 10755156
Thx for the replies but it seems I did not need the component / code afterall.
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

704 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