Solved

Label with Lines Property

Posted on 2004-04-04
5
204 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
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 25 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 25 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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