Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Помогите найти ошибку в модуле компонента


Автор: bartram 9.12.2004, 19:10
Короче, есть у меня компонент вот он:
Код

unit SynHighlighterISXCode;

{
 Inno Setup
 Copyright (C) 1998-2002 Jordan Russell
 Portions by Martijn Laan
 For conditions of distribution and use, see LICENSE.TXT.

 SynEdit highlighter for the My Inno Setup Extensions [code=delphi] section.

 To be able to compile this unit, you'll have to move the TSysPasSyn.Run field
 from the private section to the protected section. This does not affect
 TSysPasSyn's functionality so if needed you can continue using it in your
 own projects.

 $Id: SynHighlighterISXCode.pas,v 1.4 2003/01/25 11:01:53 martijn Exp $
}

interface

uses
 Classes, SynEditHighlighter, SynHighlighterPas;

type
 TSynISXCodeSynTokenID = (tkConstant, tkDirective, tkEventFunction, tkSynPasSyn);

 TSynISXCodeSyn = class(TSynPasSyn)
 private
   fLine: PChar;
   fLineNumber: Integer;
   fTokenID: TSynISXCodeSynTokenID;
   fTokenPos: Integer;
   fEventFunctionsList: TStringList;
   fConstantAttri: TSynHighlighterAttributes;
   fDirectiveAttri: TSynHighlighterAttributes;
   fEventFunctionAttri: TSynHighlighterAttributes;
 public
   constructor Create(AOwner: TComponent); override;
   destructor Destroy; override;
   function GetEol: Boolean; override;
   function GetToken: String; override;
   function GetTokenAttribute: TSynHighlighterAttributes; override;
   function GetTokenKind: integer; override;
   function GetTokenPos: Integer; override;
   procedure SetLine(NewValue: String; LineNumber: Integer); override;
   procedure Next; override;
 published
   property ConstantAttri: TSynHighlighterAttributes read fConstantAttri
     write fConstantAttri;
   property DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri
     write fDirectiveAttri;
   property EventFunctionAttri: TSynHighlighterAttributes read fEventFunctionAttri
     write fEventFunctionAttri;
 end;

procedure Register;

implementation

uses
 SysUtils, SynEditStrConst,
{$IFDEF SYN_CLX}
 QGraphics;
{$ELSE}
 Graphics;
{$ENDIF}

const
 EventFunctions: string =
   'InitializeSetup,DeInitializeSetup,CurStepChanged,NextButtonClick,' +
   'BackButtonClick,SkipCurPage,CurPageChanged,CheckPassword,NeedRestart,' +
   'UpdateReadyMemo,RegisterPreviousData,CheckSerial,InitializeWizard';

constructor TSynISXCodeSyn.Create(AOwner: TComponent);
begin
 inherited;

 fEventFunctionsList := TStringList.Create();
 fEventFunctionsList.CommaText := LowerCase(EventFunctions);

 fConstantAttri := TSynHighlighterAttributes.Create('Constant');
 AddAttribute(fConstantAttri);

 fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective);
 fDirectiveAttri.Foreground := clRed;
 AddAttribute(fDirectiveAttri);

 fEventFunctionAttri := TSynHighlighterAttributes.Create('Event function');
 fEventFunctionAttri.Style := [fsBold];
 AddAttribute(fEventFunctionAttri);
end;

destructor TSynISXCodeSyn.Destroy;
begin
 fEventFunctionsList.Free();
end;

function TSynISXCodeSyn.GetEol: Boolean;
begin
 if fTokenID <> tkSynPasSyn then
   Result := False
 else
   Result := inherited GetEol;
end;

function TSynISXCodeSyn.GetToken: string;
var
 Len: LongInt;
begin
 if fTokenID <> tkSynPasSyn then begin
   Len := Run - fTokenPos;
   SetString(Result, (FLine + fTokenPos), Len);
 end else
   Result := inherited GetToken;
end;

function TSynISXCodeSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
 case fTokenID of
   tkConstant: Result := fConstantAttri;
   tkDirective: Result := fDirectiveAttri;
   tkEventFunction: Result := fEventFunctionAttri;
   tkSynPasSyn: Result := inherited GetTokenAttribute;
 else
   Result := nil;
 end;
end;

function TSynISXCodeSyn.GetTokenKind: integer;
begin
 if fTokenID <> tkSynPasSyn then
   Result := Ord(fTokenId)
 else
   Result := Ord(High(TSynISXCodeSynTokenID)) + inherited GetTokenKind + 1;
end;

function TSynISXCodeSyn.GetTokenPos: Integer;
begin
 if fTokenID <> tkSynPasSyn then
   Result := fTokenPos
 else
   Result := inherited GetTokenPos;
end;

procedure TSynISXCodeSyn.SetLine(NewValue: String; LineNumber: Integer);
begin
 fLine := PChar(NewValue);
 Run := 0;
 fLineNumber := LineNumber;
 inherited;
end;

procedure TSynISXCodeSyn.Next;
var
 I, Len, TmpRun: Integer;
 Token: String;
begin
 fTokenPos := Run;
 fTokenID := tkSynPasSyn;
 case fLine[Run] of
   '{':
     begin
       if fLine[Run+1] = '#' then begin
         fTokenID := tkConstant;
         Inc(Run);
         repeat
           if fLine[Run] = '}' then begin
             Inc(Run);
             Break;
           end;
           Inc(Run);
         until fLine[Run] in [#0, #10, #13];
       end;
     end;
   '#':
     begin
       fTokenID := tkDirective;
       for I := Run-1 downto 0 do begin
         if fLine[I] > ' ' then begin
           // If the '#' is not the first non-whitespace character on the
           // line, then it isn't the start of a directive.
           fTokenID := tkSynPasSyn;
           Break;
         end;
       end;
       if fTokenID = tkDirective then begin
         repeat
           Inc(Run);
         until (fLine[Run] in [#0, #10, #13]);
       end;
     end;
   'A'..'Z', 'a'..'z', '_':
     begin
       TmpRun := Run;
       Inc(TmpRun);
       while fLine[TmpRun] in ['A'..'Z', 'a'..'z', '0'..'9', '_'] do
         Inc(TmpRun);
       Len := TmpRun - fTokenPos;
       SetString(Token, (FLine + fTokenPos), Len);
       if fEventFunctionsList.IndexOf(LowerCase(Token)) <> -1 then begin
         fTokenID := tkEventFunction;
         Run := TmpRun;
       end;
     end;
 end;

 if fTokenID = tkSynPasSyn then begin
   inherited;
   //Inc(Run, Length(inherited GetToken));
 end;
end;

procedure Register;
begin
 RegisterComponents('SynEdit Other', [TSynISXCodeSyn]);
end;

initialization
{$IFNDEF SYN_CPPB_1}
 RegisterPlaceableHighlighter(TSynISXCodeSyn);
{$ENDIF}
end.

он необходим для компиляции исходников популярного инсталера Inno Setup. Третий день уже мучаюсь не могу установить этот компонент, в нём ошибок куча, парочку я конечно исправил но вот остальные... Помогите пожалуйста привести код компонента в рабочее состояние! smile

Автор: Alex 9.12.2004, 20:59
bartram, Привиди исходный вариант модуля т.к. этот уже помойму ты настолько направил.

Автор: bartram 9.12.2004, 22:19
Цитата(Alex @ 9.12.2004, 20:59)
bartram, Привиди исходный вариант модуля т.к. этот уже помойму ты настолько направил.

Как раз это и есть чистый я там не менял не чего ошибочка вышла.

Автор: markowww 10.12.2004, 00:01
там тяжело разбираться без модулей, указанных в uses....

Автор: RA 10.12.2004, 01:29
bartram Какая Delphi у тебя ?

Автор: bartram 10.12.2004, 13:37
Цитата(RAdmin @ 10.12.2004, 01:29)
bartram Какая Delphi у тебя ?

Delphi 7
Цитата(markowww @ 10.12.2004, 00:01)
там тяжело разбираться без модулей, указанных в uses....

Вот держи комплект исходников
http://bartram.h14.ru/files/delphi/issrc.rar

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)