Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Label with Lines Property

Posted on 2004-04-04
5
Medium Priority
?
235 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

927 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