Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

Delphi 2.0 - incorporateing units

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
Ham
Asked:
Ham
  • 4
  • 3
1 Solution
 
StevenBCommented:
 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
 
HamAuthor Commented:
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
 
StevenBCommented:
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
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.

 
HamAuthor Commented:
Thankyou, I am happy with your reply, and I will follow up with any offenders. Paul
0
 
HamAuthor Commented:
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
 
HamAuthor Commented:
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
 
StevenBCommented:
 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now