//------------------------------------------------------------------------------
//
//1. Sch�tzung f�r Graphgr��e etc. �berpr�fen
//2. Copy von dynamischen Arrays bei neuer Allokation
//....
//
//------------------------------------------------------------------------------
unit Frame22;
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
interface
uses
//----------------------------------------------------------------------------
//local
//----------------------------------------------------------------------------
GenDefs,OwnUtils,OptionClass,Graphs,language,Utilities,Natural,Memtree,
MDIClass,Splash,
//----------------------------------------------------------------------------
//global
//----------------------------------------------------------------------------
Forms,ComCtrls,ExtCtrls,Classes,Controls,Types,StdCtrls,Menus,ImgList,
Graphics,Editor,Windows;
//----------------------------------------------------------------------------
//local
//----------------------------------------------------------------------------
type
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
TFrame2= class(TFrame)
DFA:TImage;
CFA:TImage;
PageControl1:TPageControl;
SourceTab:TTabSheet;
CfaTab:TTabSheet;
DfaTab:TTabSheet;
MeasureTab:TTabSheet;
FunktionTab:TTabSheet;
StatusBar1:TStatusBar;
TokenBox:TListBox;
ImageList1:TImageList;
FlowImages:TImageList;
ScrollBox1:TScrollBox;
ScrollBox2:TScrollBox;
Source:TEde;
Measures:TEde;
Funktion:TEde;
constructor Create(Owner:TComponent);override;
destructor Destroy;override;
procedure Loader(Nr:integer;PF:TSplashForm);
procedure findText(TF:JString;regular:boolean);
function positbyPoint(P:TPoint):integer;
function positInfo(P:TPoint;Sender:TObject):JString;
procedure positbyNode(TF:JString;Sender:TObject);
procedure Seterror(var MI:TMenuItem);
procedure setBlocknumbers();
procedure SetHints();
procedure PrintIt(PS:TStream);
procedure CreateMeasure();
procedure CreateFunktion();
procedure CreateSource(Fnr:integer;PF:TSplashForm);
procedure Zoom(G:TGraph;var Im:TImage;C:PAnsiChar;WheelDelta:integer;
var SB:TScrollBox);
procedure TokenBoxClick(Sender:TObject);
procedure TokenBoxKeyPress(Sender:TObject;var Key:Char);
procedure CreateGraph(var GR:TGraph;Img:TImage;Plong:PLongTexts;gwidth,gheight:integer);
function getSourcePoint():TPoint;
procedure sourcenames(D:TDocument);
function getPointfromNode(TF:JString):TPoint;
public
Solution:TMemTree;
BrushStyle:TBrushStyle;
PenStyle:TPenStyle;
PenWide:integer;
Drawing:boolean;
Origin,MovePt:TPoint;
DrawingTool:TGraphShape;
CurrentFile:JString;
FunktionStream:PAnsiChar;
MeasuresStream:PAnsiChar;
AllDisabled:boolean;
Page1Last:integer;
LastKeyPressed:Word;
LastClick:ViewType;
vmax:integer;
TimeSet:TDateTime;
SourceDuration:integer;
CFADuration:integer;
DFADuration:integer;
ToBeinserted:JString;
LoadTime:TDateTime;
lastkey:integer;
TimeRatio:Jstring;
end;
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
implementation
uses
Messages,SysUtils,Variants,Dialogs,jpeg,ToolWin,Buttons,Math,
StrUtils,Printers,Chart,CheckLst,Clipbrd,DateUtils,Tabs;
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
{$R *.dfm}
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
constructor TFrame2.Create(Owner:TComponent);
begin
inherited Create(Owner);
vmax:=10000;
AllDisabled:=false;
Page1Last:=0;
TimeSet:=Now;
SourceDuration:=0;
CFADuration:=0;
DFADuration:=0;
LoadTime:=Now;
LastClick:=ViewSource;
with Source do begin
oldwinproc:=WindowProc;
WindowProc:=WindProc;
end;
end;
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
destructor TFrame2.Destroy;
begin
inherited Free;
end;
//------------------------------------------------------------------
//--
//set error conditions --
//--
//------------------------------------------------------------------
procedure TFrame2.Seterror(var MI:TMenuItem);
begin
//disable Blocknumbers
Opt.r.Blocknumbers:=false;
MI.Checked:=Opt.r.Blocknumbers;
end;
//------------------------------------------------------------------
//--
//------------------------------------------------------------------
procedure TFrame2.sourcenames(D:TDocument);
var
mdiar: array of JString;
i:integer;
begin
setlength(mdiar,length(mdi.Source));
for i:=0 to length(mdi.Source)-1 do
mdiar[i]:=D.Source[i].Name;
Source.LoadNames(mdiar);
end;
//------------------------------------------------------------------
//--
//load a new source --
//--
//------------------------------------------------------------------
procedure TFrame2.Loader(Nr:integer;PF:TSplashForm);
var
Efs:JString;
begin
Efs:=mdi.Source[Nr].Name;
If FileExists(Efs) then begin
sourcenames(mdi);
CreateSource(Nr,PF);
Source.CodeCompleter.setCodeCompletionVerbs(mdi.KeyVerbs);
TimeSet:=Now;
if not (errorcount>0) and not Empty(MDI.GC.CStream,Opt.r.CFA)and(Opt.r.Semantik.Sheet<>nil) then
with Opt.r.CFA.Sheet do begin
TabVisible:=true;
CreateGraph(mdi.GC,CFA,mdi.SemL,width,height);
with mdi.GC do
if CStream<>nil then begin
width:=Opt.r.CFA.Sheet.width;
height:=Opt.r.CFA.Sheet.height;
VWidth:=0;
VHeight:=0;
ReDraw();
end;
end
else begin
Opt.r.CFA.Sheet.TabVisible:=false;
MDI.GC.CStream:=nil
end;
CFADuration:=MilliSecondsBetween(Now,TimeSet);
TimeSet:=Now;
if not (errorcount>0) and not Empty(mdi.GD.CStream,Opt.r.DFA) then
with Opt.r.DFA.Sheet do begin
TabVisible:=true;
CreateGraph(mdi.GD,DFA,mdi.NavL,width,height);
with mdi.GD do
if CStream<>nil then begin
width:=Opt.r.CFA.Sheet.width;
height:=Opt.r.CFA.Sheet.height;
VWidth:=0;
VHeight:=0;
ReDraw();
end;
end
else begin
Opt.r.DFA.Sheet.TabVisible:=false;
MDI.GD.CStream:=nil
end;
DFADuration:=MilliSecondsBetween(Now,TimeSet);
TimeSet:=Now;
if not (errorcount>0) and not Empty(MDI.Cmes,Opt.r.Measures) then begin
Opt.r.Measures.Sheet.TabVisible:=true;
CreateMeasure();
end
else begin
Opt.r.Measures.Sheet.TabVisible:=false;
MDI.Cmes:=nil
end;
if not (errorcount>0) and not Empty(MDI.CFun,Opt.r.Funktion) then begin
Opt.r.Funktion.Sheet.TabVisible:=true;
CreateFunktion();
end
else begin
Opt.r.Funktion.Sheet.TabVisible:=false;
MDI.CFun:=nil
end;
AllDisabled:=false;
LoadTime:=Now;
SetHints();
end
end;
//------------------------------------------------------------------
//--
//Printer --
//--
//------------------------------------------------------------------
procedure TFrame2.PrintIt(PS:TStream);
begin
if InSight(Opt.r.Source) then
Source.Print(CurrentFile)
else if InSight(Opt.r.CFA) then
CFA.Picture.Bitmap.SaveToStream(PS)
else if InSight(Opt.r.DFA) then
DFA.Picture.Bitmap.SaveToStream(PS)
else if InSight(Opt.r.Measures) then
Measures.Lines.SaveToStream(PS)
end;
//------------------------------------------------------------------
//--
//Posit Editor --
//--
//------------------------------------------------------------------
function TFrame2.getPointfromNode(TF:JString):TPoint;
const
white:set of ansichar=[' ',chr(Key_Tab),chr(Key_return),chr(Key_Linefeed)];
var
CFile:JString;
Cfi:integer;
Li,co:JString;
P:TPoint;
begin
Li:=getpar(S_Lin,TF);
co:=getpar(S_Col,TF);
P.x:=1;
P.y:=1;
TryStrtoInt(Li,P.y);
TryStrtoInt(co,P.x);
CFile:=getpar(S_Fil,TF);
TryStrtoInt(CFile,Cfi);
if (CFile<>'')and(Cfi<>Source.LoadedFileNumber) then begin
if (Cfi>length(MDI.Source))or(Cfi<0) then
errorn(4,
'Dateinummer korrupt, Datei='+getpar(S_Lab,TF)+', Nummer:'+IntToStr
(Cfi))
else
source.CreateHighlited(Cfi);
end;
result:=P;
end;
//------------------------------------------------------------------
//--
//ForegroundbyText --
//--
//------------------------------------------------------------------
procedure TFrame2.findText(TF:JString;regular:boolean);
var
KeyPos:integer;
begin
if TF='' then //do nothing
else if InSight(Opt.r.Source) then begin
Screen.Cursor:=crHourGlass;
if InSight(Opt.r.Source) then begin
KeyPos:=Source.FindText(TF,0,length(Source.Lines.Text),[]);
if KeyPos<>-1 then begin
Source.setCharPos(KeyPos,length(TF));
setl(Source.SearchString.S,TF);
end;
end
else if InSight(Opt.r.CFA) then
mdi.GC.GraphPositbyText(TF,CFA)
else if InSight(Opt.r.DFA) then
mdi.GC.GraphPositbyText(TF,DFA)
else if InSight(Opt.r.Funktion) then begin
KeyPos:=Funktion.FindText(TF,0,length(Funktion.Lines.Text),[]);
if KeyPos<>-1 then begin
Funktion.setCharPos(KeyPos,length(TF));
setl(Source.SearchString.S,TF)
end;
end;
ViewList.Per[F2].Node:=Source.CaretPos.y;
Screen.Cursor:=crDefault;
end
else if InSight(Opt.r.Funktion) then begin
Screen.Cursor:=crHourGlass;
KeyPos:=Funktion.FindText(TF,0,length(Funktion.Lines.Text),[]);
if KeyPos<>-1 then begin
Funktion.setCharPos(KeyPos,length(TF));
setl(Source.SearchString.S,TF)
end;
Screen.Cursor:=crDefault;
end;
end;
//------------------------------------------------------------------
//--
//ForegroundbyNode --
//--
//------------------------------------------------------------------
procedure TFrame2.positbyNode(TF:JString;Sender:TObject);
var P:TPOint;Wo:JString;
begin
if (Sender<>Source)and InSight(Opt.r.Source) then begin
Opt.r.Source.Sheet.PageControl.ActivePage:=Opt.r.Source.Sheet;
//Source.positbyNode(TF);
P:=getPointfromNode(TF);
Wo:=getpar(S_Lab,TF);
Source.markWord(P.Y,P.x,length(Wo));
if ViewList<>nil then
ViewList.Per[F2].Node:=Source.CaretPos.y;
end;
if InSight(Opt.r.CFA) then begin
LastClick:=ViewCFA;
mdi.GC.GraphPositbyText(Functor(TF),CFA);
end;
If InSight(Opt.r.DFA) then begin
LastClick:=ViewDFA;
mdi.GC.GraphPositbyText(Functor(TF),DFA);
end;
end;
//------------------------------------------------------------------
//--
//ForegroundbyNode --
//--
//------------------------------------------------------------------
function TFrame2.positbyPoint(P:TPoint):integer;
var
se,co:integer;
Key:JString;Q:TPoint;
begin
positbyPoint:=0;
Key:='';
If InSight(Opt.r.CFA) then begin
LastClick:=ViewDFA;
se:=mdi.GC.FindGraphNode(CFA,P);
if se>0 then begin
positbyPoint:=se;
mdi.GC.Selected:=se;
co:=mdi.GC.Maps(se).Tree;
if (co>=0)and(co<=length(mdi.GC.Content^.items)) then
Key:=mdi.GC.Content^.items[co].Text;
mdi.GC.GraphPositbyNode(se,CFA);
end;
end;
If InSight(Opt.r.DFA) then begin
LastClick:=ViewDFA;
se:=mdi.GD.FindGraphNode(DFA,P);
if se>0 then begin
positbyPoint:=se;
mdi.GD.Selected:=se;
co:=mdi.GD.Maps(se).Tree;
if (co>=0)and(co<=length(mdi.GD.Content^.items)) then
Key:=mdi.GD.Content^.items[co].Text;
mdi.GD.GraphPositbyNode(se,DFA);
end;
end;
if InSight(Opt.r.Source) then begin
Opt.r.Source.Sheet.PageControl.ActivePage:=Opt.r.Source.Sheet;
if Key='' then
Source.markLinePos(P.y,1)
else if Key>'' then begin
//positbynode(Key)
Q:=getPointfromNode(Key);
Source.markLinePos(Q.Y,Q.x);
positbyPoint:=1;
end;
end;
Screen.Cursor:=crDefault;
end;
//------------------------------------------------------------------
//--
//ForegroundbyNode --
//--
//------------------------------------------------------------------
function TFrame2.positInfo(P:TPoint;Sender:TObject):JString;
var
se,co:integer;
Key:JString;
begin
Key:='';
If InSight(Opt.r.CFA) then begin
LastClick:=ViewDFA;
se:=mdi.GC.FindGraphNode(CFA,P);
if se>0 then begin
mdi.GC.Selected:=se;
co:=mdi.GC.Maps(se).Tree;
if (co>=0)and(co<=length(mdi.GC.Content^.items)) then
Key:=Functor(mdi.GC.Content^.items[co].Text);
end;
end;
If InSight(Opt.r.DFA) then begin
LastClick:=ViewDFA;
se:=mdi.GD.FindGraphNode(DFA,P);
if se>0 then begin
mdi.GD.Selected:=se;
co:=mdi.GC.Maps(se).Tree;
if (co>=0)and(co<=length(mdi.GD.Content^.items)) then
Key:=Functor(mdi.GD.Content^.items[co].Text);
end;
end;
positInfo:=Key;
end;
//------------------------------------------------------------------
//Zoom Handler --
//--
//------------------------------------------------------------------
procedure TFrame2.Zoom(G:TGraph;var Im:TImage;C:PAnsiChar;WheelDelta:integer;
var SB:TScrollBox);
function wheelup:boolean;
begin
wheelup:=WheelDelta<0
end;
function wheeldown:boolean;
begin
wheeldown:=WheelDelta<0
end;
const
facn=95;
facd=100;
facmax=2;
facmin=0.95*0.95*0.95;
var
vw,vh,vt,vl:integer;
begin
vw:=G.VWidth;
vh:=G.VHeight;
vt:=G.VTop;
vl:=G.VLeft;
if wheelup() then begin
G.VWidth:=(facd*G.VWidth)div facn;
G.VHeight:=(facd*G.VHeight)div facn;
end
else begin
G.VWidth:=(facn*G.VWidth)div facd;
G.VHeight:=(facn*G.VHeight)div facd;
end;
if G.VWidth<G.width then begin
G.VTop:=(G.height-G.VHeight)div 2;
G.VLeft:=(G.width-G.VWidth)div 2;
end;
if (G.VWidth<facmin*G.width)or(G.VHeight<100)or
(G.VHeight>Screen.height*facmax) then begin
G.VWidth:=vw;
G.VHeight:=vh;
G.VTop:=vt;
G.VLeft:=vl;
end;
SB.HorzScrollBar.Range:=G.VWidth;
SB.VertScrollBar.Range:=G.VHeight;
end;
//------------------------------------------------------------------
//Function Blocknumbers --
//--
//------------------------------------------------------------------
procedure TFrame2.setBlocknumbers();
var
S,Att:JString;
P,bnr,Lin,Last,i,ii,ll:integer;
begin
if mdi.SemL<>nil then
with Source,mdi do begin
for P:=1 to Blockarray.count do
Blockarray.lines[P]:=-1;
ll:=length(SemL^.items);
for ii:=0 to ll-1 do begin
S:=SemL^.items[ii].Text;
Att:=getattribute(S_Bnr,S);
TryStrtoInt(Att,bnr);
Att:=getattribute(S_Lin,S);
TryStrtoInt(Att,Lin);
if (Lin>0)and(Lin<Blockarray.count)and(Blockarray.lines[Lin]<0) then
Blockarray.lines[Lin]:=bnr;
end;
Last:=-1;
for i:=1 to Blockarray.count-1 do begin
if Blockarray.lines[i]>0 then
Last:=Blockarray.lines[i]
else if (Last>0)and(Blockarray.lines[i]<0) then
Blockarray.lines[i]:=Last;
end;
end;
end;
//------------------------------------------------------------------
//--
//create Measures --
//--
//------------------------------------------------------------------
procedure TFrame2.CreateSource(Fnr:integer;PF:TSplashForm);
var T1,T2,T31,T32,T33:integer;Tim1:TDatetime;TT:TimeTripel;
begin
//check modification
Opt.r.Source.Sheet.TabVisible:=true;
PageControl1.ActivePage:=Opt.r.Source.Sheet;
//now load frames
Tim1:=Now;
TimeSet:=Now;
mdi.Source[Fnr].Age:=FormatDateTime('yyyy.mm.dd hh:ss',
getFileAge(mdi.Source[Fnr].Name));
Source.ReadOnly:=false;
Source.lang:=lang;
Source.SyntaxHighlight:=Opt.r.SyntaxHighlight;
Source.Syntaxbold:=Opt.r.Syntaxbold;
Source.LoadHighLites(Opt.r.Highlites);
T1:=milliSecondsBetween(Now,Tim1);
PF.Progress(5);
//
Tim1:=Now;
Source.LoadAttributes(mdi.Cattr);
T2:=milliSecondsBetween(Now,Tim1);
PF.Progress(35);
//
Source.LineNumbers:=Opt.r.LineNumbers;
Source.Blocknumbers:=Opt.r.Blocknumbers;
TT:=Source.CreateHighlited(Fnr);
T31:=TT.T1;T32:=TT.T2;T33:=TT.T3;
PF.Progress(5);
//done
setBlocknumbers();
setl(Source.SearchString.S,'');
SourceDuration:=MilliSecondsBetween(Now,TimeSet);
mdi.Fnr:=Fnr;
//Source.Mark();
PF.Progress(5);
TimeRatio:='';
if IsDebuggerPresent and (T2>100)then begin
if T2>1000 then
TimeRatio:=' F2=/'+IntToStr(T1 div 1000)+'/'+IntToStr(T2 div 1000)+'/'
+IntToStr(T31 div 1000)+'/'+IntToStr(T32 div 1000)+'/'+IntToStr(T33 div 1000)+' sec'
else
TimeRatio:=' F2=/'+IntToStr(T1)+'/'+IntToStr(T2)+'/'+IntToStr(T31)
+'/'+IntToStr(T32)+'/'+IntToStr(T33)+' msec'
end;
end;
//------------------------------------------------------------------
//--
//create Measures --
//--
//------------------------------------------------------------------
procedure TFrame2.CreateGraph(var GR:TGraph;Img:TImage;Plong:PLongTexts;gwidth,gheight:integer);
begin
with GR do begin
getgraph(PLong^);
Im:=Img;
Imclear:=Img;
width:=gwidth;
height:=gheight;
end;
end;
//------------------------------------------------------------------
//--
//create Measures --
//--
//------------------------------------------------------------------
procedure TFrame2.CreateMeasure();
var
Line:JString;
F:TFont;
begin
Measures.Lines.Clear;
Measures.ReadOnly:=false;
if mdi.Cmes<>nil then begin
FunktionStream:=mdi.Cmes;
Measures.Paragraph.FirstIndent:=20;
F:=TFont.Create;
F.Name:=Opt.r.FontName;
F.size:=Opt.r.FontSize;
F.Style:=Opt.r.FontStyle;
F.Color:=Opt.r.FontColor;
OpenStream(mdi.Cmes);
while not eofs do begin
Line:=GetNextRec(mdi.Cmes);
Measures.Lines.add(Line)
end;
end;
Measures.ReadOnly:=true;
end;
//------------------------------------------------------------------
//
//create Funktion --
//
//------------------------------------------------------------------
procedure TFrame2.CreateFunktion();
var
SN,FN:AnsiString;
begin
if (mdi.CFun<>nil) then begin
FN:=IntToStr(Source.getFileNumber(Source.LoadedFile));
SN:=makexmlnode('Root',1,1,1);
TimeSet:=Now;
Solution:=TMemTree.Create(SN,0);
Solution.LoadTreeFromStream(MDI.CFun);
Displayres(Solution,Funktion);
//posit on first line
Funktion.mark();
Funktion.markLinePos(1,1);
end
else
Funktion.CreateDummyFile();
Funktion.ReadOnly:=true;
end;
//------------------------------------------------------------------
//
//Box Click --
//
//------------------------------------------------------------------
procedure TFrame2.TokenBoxClick(Sender:TObject);
begin
if TokenBox.ItemIndex>0 then begin
Clipboard.SetTextBuf(PChar(TokenBox.items[TokenBox.ItemIndex]));
Source.PasteFromClipboard;
TokenBox.Visible:=false;
Source.SetFocus
end
end;
//------------------------------------------------------------------
//--
//Box key down --
//--
//------------------------------------------------------------------
procedure TFrame2.TokenBoxKeyPress(Sender:TObject;var Key:Char);
begin
if ord(Key)=Key_Escape then begin
TokenBox.Visible:=false;
Source.SetFocus
end
else if ord(Key) in [Key_up,Key_down,Key_Left,Key_Right] then
else if ord(Key)=Key_return then
TokenBoxClick(Sender)
end;
//------------------------------------------------------------------
//
//SetHints --
//
//------------------------------------------------------------------
procedure TFrame2.SetHints();
begin
with Source do begin
if Opt.r.language=english then begin
if Source<>nil then
Hint:=HintBox('Source'+crlf+ExtractFileName(LoadedFile));
if CFA<>nil then
CFA.Hint:=HintBox('Controlflow'+crlf+ExtractFileName(LoadedFile));
if DFA<>nil then
DFA.Hint:=HintBox('Dataflow'+crlf+ExtractFileName(LoadedFile));
if Measures<>nil then
Measures.Hint:=HintBox('Measures'+crlf+ExtractFileName(LoadedFile));
if Funktion<>nil then
Funktion.Hint:=HintBox('Function'+crlf+ExtractFileName(LoadedFile));
end
else begin
if Source<>nil then
Hint:=HintBox('Quelle'+crlf+ExtractFileName(LoadedFile));
if CFA<>nil then
CFA.Hint:=HintBox('Kontrollfluss'+crlf+ExtractFileName(LoadedFile));
if DFA<>nil then
DFA.Hint:=HintBox('Datenfluss'+crlf+ExtractFileName(LoadedFile));
if Measures<>nil then
Measures.Hint:=HintBox('Messwerte'+crlf+ExtractFileName(LoadedFile));
if Funktion<>nil then
Funktion.Hint:=HintBox('Funktion'+crlf+ExtractFileName(LoadedFile));
end;
end;
end;
//------------------------------------------------------------------
//
//SetHints --
//
//------------------------------------------------------------------
function TFrame2.getSourcePoint():TPoint;
var
P:TPoint;
begin
P.x:=Source.CaretPos.x+1;
P.y:=Source.CaretPos.y+1;
getSourcePoint:=P
end;
//------------------------------------------------------------------
//--
//Ende dieser Quelle --
//--
//------------------------------------------------------------------
end.
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet)
¤
|
Haftungshinweis
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.
|