Solved

Completely stuck on a problem with incompatible types!

Posted on 2001-07-25
7
281 Views
Last Modified: 2010-04-06
I wrote a component for a line which could go in any direction (diagonally, horizontally, vertically) and that could have an arrow head at any end.  I am having a problem when I try to create a line dynamically at runtime from the text in a file.  The text specifying the properties of the line is held in a string array....but Delphi is unhappy with this as it says that my string is not the required type to set properties such as the arrow type and style of line.  Fair enough.  So, now I have tried to put a function into the code for the component to allow it to translate the string into the required type....only now I'm getting incompatible type errors.  I'm just completely stuck!
I've attached the code I have below and if anyone has any ideas I'd really like to hear from them!
Thanks,
Xanthe


unit XantheAllFunctionLine;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TXantheAFLineStyles = (lsHorizontal,lsVertical,lsDiagonalUp,lsDiagonalDown);
  TXantheAFLineStyle  = set of TXantheAFLineStyles;
  TXantheArrowTypes = (atHorizontalLeft,atHorizontalRight,atVerticalTop,atVerticalBottom,atDiagonalUpTop,atDiagonalUpBottom,atDiagonalDownTop,atDiagonalDownBottom,atNone);
  TXantheArrowType = set of TXantheArrowTypes;

  TXantheAFLine = class(TGraphicControl)
    private
      FStyle : TXantheAFLineStyle;
      FArrow : TXantheArrowType;
      FPen : TPen;
      FColour : TColor;
      procedure SetStyle(NewStyle:TXantheAFLineStyle);
      procedure SetArrowType(NewStyle:TXantheArrowType);
      procedure SetColour(V:TColor);
    protected
      procedure Paint; override;
    public
      constructor Create(AOwner:TComponent); override;
      destructor Free;
    published
      procedure PenChange(Sender:TObject);
      property Height;
      property Left;
      property Pen:TPen read FPen write FPen;
      property ShowHint;
      property Style:TXantheAFLineStyle read FStyle write SetStyle default [lsHorizontal];
      property Arrow:TXantheArrowType read FArrow write SetArrowType default [atNone];
      property Colour:TColor read fColour write SetColour default clBlack;
      property Top;
      property Width;
      function ChangeArrow(S:string):TXantheArrowType;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Xanthe',[TXantheAFLine]);
end;

constructor TXantheAFLine.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  FPen := TPen.Create;
  FPen.OnChange := PenChange;
  Height := 40;
  Width := Height;
  Style := [lsHorizontal];
  Arrow := [atNone];
  Colour := clBlack;
end;

destructor TXantheAFLine.Free;
begin
  FPen.Free;
  inherited Free;
end;

procedure TXantheAFLine.Paint;
var
  X : Integer;
  Y : Integer;
  W,W1 : Integer;
  H,H1 : Integer;
begin
  Canvas.Pen := Pen;
  Canvas.Pen.Color:=FColour;
  X := Pen.Width div 2;
  Y := X;
  W := Width - X;
  W1:= W div 2;
  H := Height - Y;
  H1:= H div 2;
  if X<Pen.Width/2 then
    begin
      Dec(W);
      Dec(H);
    end;
  if lsHorizontal in FStyle then
    begin
      Canvas.PenPos := Point(X,H1);
      Canvas.LineTo(W,H1);
      if atHorizontalLeft in FArrow then
         begin
              Canvas.PenPos := Point(X,H1);
              Canvas.LineTo(W1 div 2,Y + (H1 div 2));
              Canvas.PenPos := Point(X,H1);
              Canvas.LineTo(W1 div 2,H - (H1 div 2));
         end;
      if atHorizontalRight in FArrow then
         begin
              Canvas.PenPos := Point(W,H1);
              Canvas.LineTo(W - W1 div 2,Y + (H1 div 2));
              Canvas.PenPos := Point(W,H1);
              Canvas.LineTo(W - W1 div 2,H - (H1 div 2));
         end;
    end;
  if lsVertical in FStyle then
    begin
      Canvas.PenPos := Point(W1,Y);
      Canvas.LineTo(W1,H);
      if atVerticalTop in FArrow then
         begin
              Canvas.PenPos := Point(W1,Y);
              Canvas.LineTo(W1 div 2,Y + (H1 div 2));
              Canvas.PenPos := Point(W1,Y);
              Canvas.LineTo(W1 + W1 div 2,Y + (H1 div 2));
         end;
      if atVerticalBottom in FArrow then
         begin
              Canvas.PenPos := Point(W1,H);
              Canvas.LineTo(W - W1 div 2,H - (H1 div 2));
              Canvas.PenPos := Point(W1,H);
              Canvas.LineTo(W1 - W1 div 2,H - (H1 div 2));
         end;
    end;
  if lsDiagonalUp in FStyle then
    begin
      Canvas.PenPos := Point(X,H);
      Canvas.LineTo(W,Y);
      if atDiagonalUpTop in FArrow then
         begin
              Canvas.PenPos := Point(W,Y);
              Canvas.LineTo(W - W1 div 2,Y);
              Canvas.PenPos := Point(W,Y);
              Canvas.LineTo(W,Y + (H1 div 2));
         end;
      if atDiagonalUpBottom in FArrow then
         begin
              Canvas.PenPos := Point(X,H);
              Canvas.LineTo(X,H - (H1 div 2));
              Canvas.PenPos := Point(X,H);
              Canvas.LineTo(W1 div 2,H);
         end;
    end;
  if lsDiagonalDown in FStyle then
    begin
       Canvas.PenPos := Point(X,Y);
       Canvas.LineTo(W,H);
      if atDiagonalDownTop in FArrow then
         begin
              Canvas.PenPos := Point(X,Y);
              Canvas.LineTo(X + W1 div 2,Y);
              Canvas.PenPos := Point(X,Y);
              Canvas.LineTo(X,H1 - (H1 div 2));
         end;
      if atDiagonalDownBottom in FArrow then
         begin
              Canvas.PenPos := Point(W,H);
              Canvas.LineTo(W - W1 div 2,H);
              Canvas.PenPos := Point(W,H);
              Canvas.LineTo(W,H1 + (H1 div 2));
         end;
    end;
end;

procedure TXantheAFLine.PenChange(Sender:TObject);
begin
  Invalidate;
end;

procedure TXantheAFLine.SetStyle(NewStyle:TXantheAFLineStyle);
begin
  if NewStyle<>FStyle then
    begin
      FStyle := NewStyle;
      Invalidate;
    end;
end;

procedure TXantheAFLine.SetArrowType(NewStyle:TXantheArrowType);
begin
  if NewStyle<>FArrow then
    begin
      FArrow := NewStyle;
      Invalidate;
    end;
end;

procedure TXantheAFLine.SetColour(V:TColor);
begin
  if V<>FColour then
    begin
      FColour := V;
      Invalidate;
    end;
end;

function TXantheAFLine.ChangeArrow(S:string):TXantheArrowType;
begin
     if (S='bsNone') then
        ChangeArrow:=atNone;
end;

(this last function doesn't work - gives the incompatible types error)
0
Comment
Question by:xanthe
  • 3
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6317038
Hi xanthe@lc,

you use set of .... so you need to use "[...]", it would be something like this:

function TXantheAFLine.ChangeArrow(S:string):TXantheArrowType;
begin
     if (S='bsNone') then
        ChangeArrow:=[atNone];
end;
------
Igor.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6317051
well, i guess you need a translation of the names of your Type enumerations

like
TXantheAFLineStyles = (lsHorizontal,lsVertical,lsDiagonalUp,lsDiagonalDown);
 
Const
TXantheAFLineStylesName : Array[lsHorizontal..lsDiagonalDown] of string := ('lsHorizontal','lsVertical','lsDiagonalUp','lsDiagonalDown');

and a method which does translate this

like
Function TXantheAFLine.StyleNameToStyle(AName : String) : TXantheAFLineStyles;
var i : Integer;
begin
  i := low(TXantheAFLineStylesName);
  while (I <= High(TXantheAFLineStylesName) and (TXantheAFLineStylesName[i] <> AString) do inc(i);
  if i <= High(TXantheAFLineStylesName) then
    Result := TXantheAFLineStyles(Ord(i))
  else
    raise exception.create('Invalid name');
end;

not sure about this line
    Result := TXantheAFLineStyles(Ord(i))

just from head
maybe there is a better way,
because the ide can enumerate the names

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6317055
you're right, igor,
i should read to end of q
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 9

Expert Comment

by:ITugay
ID: 6317073
meikl :-)
may be, may be....

another thing that result of function should be
TXantheArrowTypes
   instead of
TXantheArrowType

------
Igor.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6317093
? there is no result assigned (last function from xanthe)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6317105
Hi xanthe@lc,

I mean.ChangeArrow function.

function TXantheAFLine.ChangeArrow(S:string):TXantheArrowType[s?];

May be I miss something, but result is assigned.

     if (S='bsNone') then
        ChangeArrow := atNone; // old style result assignment

-----
Igor.
 
0
 

Author Comment

by:xanthe
ID: 6317167
Igor,
Fantastic..yet again!  I think that is the one thing that I didn't try!  Thanks also to meikl who replied here.  Incidentally, is it really 5 o'clock in the morning when you are writing this? - no wonder you know so much if you're that keen!
Thanks again,
Xanthe
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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