Solved

Delphi 2.0 - incorporateing units

Posted on 1997-08-18
7
906 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
Comment Utility
 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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

Author Comment

by:Ham
Comment Utility
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
Comment Utility
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
Comment Utility
 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

12 Experts available now in Live!

Get 1:1 Help Now