Solved

Label with Lines Property

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 152
Newbie Thread Programming 1 118
delphi exception 7 58
FMX enumerated colours 2 73
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now