Solved

Delphi 2.0 - incorporateing units

Posted on 1997-08-18
7
910 Views
Last Modified: 2012-05-04
Hello,

I have stumbled across Delphi programmers Corner achieve on the net. They offer of freeware (units/components) - some of which I have copied.

Q1. My problem is how do I incorporate their prewritten units successfully.
Q2. I have a particular example I would like solved.

(I realise I place the unit's name in the 'implementation uses' area of the unit calling it, but where do I go from there?)

The name of the unit is Aligrid (it aligns text in a TStringGrid) See following for Aligrid code:

************************************************************
unit Aligrid;

{Usage: There is one additional property
 "Alignment", the possible values are:
 alRight, alLeft, alCenter.
 This alignment hold for the complete grid;
 I'm currently working on one with an alignment
 for each cell.}

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Grids;

type TMyAlign = ( alRight, alLeft, alCenter);

type
  TStringAlignGrid = class(TStringGrid)
  private
    FAlign : TMyAlign;
    function GetAlign:TMyAlign;
    procedure SetAlign(const Value: TMyAlign);
    procedure Initialize;
  protected
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
      AState: TGridDrawState); override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Alignment: TMyAlign read GetAlign write SetAlign default alLeft;
  end;

procedure Register;

implementation

constructor TStringAlignGrid.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Initialize;
end;

procedure TStringAlignGrid.Initialize;
begin
   FAlign := alLeft;
end;

function TStringAlignGrid.GetAlign: TMyAlign;
begin
   Result := FAlign;
end;

procedure TStringAlignGrid.SetAlign(const Value: TMyAlign);
begin
   FAlign := Value;
   Invalidate;
end;


procedure TStringAlignGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
  AState: TGridDrawState);

  procedure DrawCellText;
  var
    Text: array[0..255] of Char;
    l : Integer;
    Temp : TRect;
    Alignment : TMyAlign;
  begin
    StrPCopy(Text, Cells[ACol, ARow]);
    l:=Canvas.TextWidth(Cells[ACol, ARow]);
    Temp := ARect;
    Alignment := FAlign;
    if Alignment in [alCenter] then
       if l < (Temp.Right-Temp.Left) then begin
          l := ((Temp.Right-Temp.Left) - l ) div 2;
          Temp.Left := Temp.Left + l - 1;
          Temp.Right := Temp.Right - l + 1 ;
       end;
    if Alignment in [alRight] then begin
       Temp.Left := Temp.Right -l - 4 ;
       if temp.left < ARect.Left then
          temp.left := ARect.Left;
    end;
    ExtTextOut(Canvas.Handle, Temp.Left+2, Temp.Top + 2,  ETO_CLIPPED or
      ETO_OPAQUE, @Temp, Text, StrLen(Text), nil);
  end;

begin
  if DefaultDrawing then DrawCellText;
  {inherited DrawCell(ACol, ARow, ARect, AState);}
end;

procedure Register;
begin
  RegisterComponents('Beispiele', [TStringAlignGrid]);
end;

end.    
***********************************************************


0
Comment
Question by:Ham
  • 4
  • 3
7 Comments
 
LVL 4

Accepted Solution

by:
StevenB earned 70 total points
ID: 1341702
 What you have here is not simply a unit to be included in your code, but a custom written component. You can tell this as it has a register procedure. This procedure is used by Delphi to add the new component to the library of components (VCL). What you need to do then is add this component to your copy of Delphi.
  I'm currently running Delphi3 so I'm doing this from memory:

  Find the Install new components dialog from the menu. Ignore anything to do with OCX's for the moment and concentrate on the bottom window of the dialog. There is an Add button, or similar. After you click it you should be able to browse to the *.pas file that you are trying to install. select this and it should appear in the bottom window of the install dialog. OK this dialog and Delphi will recompile your VCL. There should now be a new tab (Beispiele) with the new component on it. Use this exactly as you do other components.

  If you want any more info then leave a comment.

  Steven.
0
 

Author Comment

by:Ham
ID: 1341703
Okay that solved that particular one, but Im not successful with some other custom written units - for instance:

1) Can I still make a component with a compiled unit *.dcu (I get Error cannot find *.pas)

or

2) Error 16-Bit (was this made for Delphi 1.0?)

Thankyou
Ham
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1341704
1) Yes you can add a component from a *.dcu file, however there are a few reasons for the message you describe. Some components are just badly written, and don't work. In this case there is nothing you can do. The more sinister problem is that there is a bug in Delphi. If the string that forms your search path excedes 250 characters then Delphi starts to behave very strangely and throws up this error. The solution is to put all your components in one directory, so that the search path doesn't grow with every new component (incidentally I seem to recall that you have to edit the search path manually when you uninstall a component, an oversight on the part of Borland). Check your search path, and if that doesn't seem to be the problem then mail me the offending component and I'll check it on my machine:

stemail@dial.pipex.com

2) Yes it very much seems that way. I've never encountered this message, but 16-bit code can only be intended for D1.

  Steven
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 

Author Comment

by:Ham
ID: 1341705
Thankyou, I am happy with your reply, and I will follow up with any offenders. Paul
0
 

Author Comment

by:Ham
ID: 1341706
PS. Ive noticed that there is a limit to the amount of components that can be kept at once. After Delphi decides that the next component that you are tring to recompile is one to many - it decides to clean out your entire library of components - this makes one very angry fellow, but Im lucky I have a squeezy cow (a cow that you squeeze when mad - rather than put your fist through the screen - I suggest all programmers purchase one).
0
 

Author Comment

by:Ham
ID: 1341707
PS. Ive noticed that there is a limit to the amount of components that can be kept at once. After Delphi decides that the next component that you are tring to recompile is one to many - it decides to clean out your entire library of components - this makes one very angry fellow, but Im lucky I have a squeezy cow (a cow that you squeeze when mad - rather than put your fist through the screen - I suggest all programmers purchase one).
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1341708
 I'm not aware of any limit to the actual number of components that can be added, although It's entirely possible. The real one to watch is definately the Search path length, this is the sort of problem that can drive people to extremes of anger that cannot be relieved by squeezing cows.
  I'm still receiving email notification on this question, so if any more problems crop up then put them in as comments, or mail me direct and I'll see if there's anything I can do.

  Good Luck, Steven.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 327
Delphi XE10, DigitalPersona Fingerprint reader and MySQL 6 334
Delphi selector screen 2 84
Microsoft Access 97 and Delphi XE2 9 56
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

829 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