Solved

Label with Lines Property

Posted on 2004-04-04
5
216 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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