📄 wsclasses.pas
字号:
const
wsFormName = '_wsFormName_';
implementation
uses wsRes, ShellApi, wsDB, wsBlocks, wsMain
{$WARNINGS OFF}
, FileCtrl
{$WARNINGS ON}
;
{ TWorkflowDefinitions }
function TWorkflowDefinitions.Add: TWorkflowDefinition;
begin
result := TWorkflowDefinition(inherited Add);
end;
constructor TWorkflowDefinitions.Create(AOwner: TComponent);
begin
inherited Create(AOwner, TWorkflowDefinition);
end;
function TWorkflowDefinitions.FindByKey(AKey: string): TWorkflowDefinition;
var
c: integer;
begin
result := nil;
for c := 0 to Count - 1 do
if AKey = Items[c].Key then
begin
result := Items[c];
break;
end;
end;
function TWorkflowDefinitions.FindByName(
AName: string): TWorkflowDefinition;
var
c: integer;
begin
result := nil;
for c := 0 to Count - 1 do
if SameText(AName, Items[c].Name) then
begin
result := Items[c];
break;
end;
end;
function TWorkflowDefinitions.FindNewName: string;
var
c: integer;
begin
c := 0;
repeat
inc(c);
result := Format('%s %d', [_str(SWorkflowDefinition), c]);
until (FindByName(result) = nil);
end;
function TWorkflowDefinitions.GetItem(Index: integer): TWorkflowDefinition;
begin
result := TWorkflowDefinition(inherited Items[Index]);
end;
{ TWorkflowDefinition }
procedure TWorkflowDefinition.AssignFromDiagram(ADiagram: TWorkflowDiagram);
var
TempStream: TMemoryStream;
oldName: string;
begin
TempStream := TMemoryStream.Create;
try
oldName := ADiagram.Owner.Name;
ADiagram.Owner.Name := wsFormName;
ADiagram.SaveToStream(TempStream);
ADiagram.Owner.Name := oldName;
TempStream.Position := 0;
oldName := FDiagram.Owner.Name;
FDiagram.Owner.Name := wsFormName;
FDiagram.LoadFromStream(TempStream);
FDiagram.Owner.Name := oldName;
finally
TempStream.Free;
end;
Changed(false);
end;
procedure TWorkflowDefinition.AssignToDiagram(ADiagram: TWorkflowDiagram);
var
TempStream: TMemoryStream;
oldName: string;
begin
TempStream := TMemoryStream.Create;
try
oldName := FDiagram.Owner.Name;
FDiagram.Owner.Name := wsFormName;
FDiagram.SaveToStream(TempStream, true);
FDiagram.Owner.Name := oldName;
TempStream.Position := 0;
oldName := ADiagram.Owner.Name;
ADiagram.Owner.Name := wsFormName;
ADiagram.LoadFromStream(TempStream, true);
ADiagram.Owner.Name := oldName;
finally
TempStream.Free;
end;
end;
constructor TWorkflowDefinition.Create(Collection: TCollection);
begin
inherited Create(Collection);
FContainer := TForm.Create(nil);
FDiagram := TWorkflowDiagram.Create(FContainer);
FDiagram.Parent := FContainer;
end;
destructor TWorkflowDefinition.Destroy;
begin
FContainer.Free;
FContainer := nil;
FDiagram := nil;
inherited;
end;
procedure TWorkflowDefinition.SetKey(const Value: string);
begin
if FKey <> Value then
begin
FKey := Value;
//Changed(false);
end;
end;
procedure TWorkflowDefinition.SetName(const Value: string);
begin
if FName <> Value then
begin
FName := Value;
//Changed(false);
end;
end;
(*{ TWorkflowInstances }
function TWorkflowInstances.Add: TWorkflowInstance;
begin
result := TWorkflowInstance(inherited Add);
end;
constructor TWorkflowInstances.Create(AOwner: TComponent);
begin
inherited Create(AOwner, TWorkflowInstance);
end;
function TWorkflowInstances.GetItem(Index: integer): TWorkflowInstance;
begin
result := TWorkflowInstance(inherited Items[Index]);
end;*)
{ TWorkflowInstance }
procedure TWorkflowInstance.AssignFromDiagram(ADiagram: TWorkflowDiagram; State: boolean);
var
TempStream: TMemoryStream;
oldName: string;
begin
TempStream := TMemoryStream.Create;
try
oldName := ADiagram.Owner.Name;
ADiagram.Owner.Name := wsFormName;
if State then
ADiagram.SaveStateToStream(TempStream)
else
ADiagram.SaveToStream(TempStream);
ADiagram.Owner.Name := oldName;
TempStream.Position := 0;
oldName := FDiagram.Owner.Name;
FDiagram.Owner.Name := wsFormName;
if State then
FDiagram.LoadStateFromStream(TempStream)
else
FDiagram.LoadFromStream(TempStream);
FDiagram.Owner.Name := oldName;
finally
TempStream.Free;
end;
end;
procedure TWorkflowInstance.AssignToDiagram(ADiagram: TWorkflowDiagram; State: boolean);
var
TempStream: TMemoryStream;
oldName: string;
begin
TempStream := TMemoryStream.Create;
try
oldName := FDiagram.Owner.Name;
FDiagram.Owner.Name := wsFormName;
if State then
FDiagram.SaveStateToStream(TempStream, true)
else
FDiagram.SaveToStream(TempStream, true);
FDiagram.Owner.Name := oldName;
TempStream.Position := 0;
oldName := ADiagram.Owner.Name;
ADiagram.Owner.Name := wsFormName;
if State then
ADiagram.LoadStateFromStream(TempStream, true)
else
ADiagram.LoadFromStream(TempStream, true);
ADiagram.Owner.Name := oldName;
finally
TempStream.Free;
end;
end;
constructor TWorkflowInstance.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FStatus := wsNotStarted;
FContainer := TForm.Create(nil);
FDiagram := TWorkflowDiagram.Create(FContainer);
FDiagram.Parent := FContainer;
FDiagram.FWorkflowInstance := Self;
end;
procedure TWorkflowInstance.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty('Diagram', LoadDiagramProp, StoreDiagramProp, true);
end;
destructor TWorkflowInstance.Destroy;
begin
FContainer.Free;
FContainer := nil;
FDiagram := nil;
inherited;
end;
procedure TWorkflowInstance.LoadDiagramProp(Reader: TReader);
var
DiagramStr: string;
begin
DiagramStr := Reader.ReadString;
Case Status of
wsRunning:
StateFromString(FDiagram, DiagramStr);
else
{wsNotStarted, wsFinished}
DiagramFromString(FDiagram, DiagramStr);
end;
end;
procedure TWorkflowInstance.StoreDiagramProp(Writer: TWriter);
var
DiagramStr: string;
begin
Case Status of
wsRunning:
DiagramStr := StateToString(FDiagram);
else
{wsNotStarted, wsFinished}
DiagramStr := DiagramToString(FDiagram);
end;
Writer.WriteString(DiagramStr);
end;
{ TWorkflowDiagram }
constructor TWorkflowDiagram.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SleepVisual := 0;
MaximumIdle := 100;
FVariables := TWorkflowVariables.Create(Self, TWorkflowVariable);
FAttachments := TWorkflowAttachments.Create(Self);
SnapGrid.Visible := true;
SnapGrid.SnapToRuler := true;
LeftRuler.Visible := true;
TopRuler.Visible := true;
Color := clWhite;
end;
destructor TWorkflowDiagram.Destroy;
begin
FAttachments.Free;
FVariables.Free;
inherited;
end;
function TWorkflowDiagram.DiagramStreamClass: TatDiagramClass;
begin
result := TWorkflowStreamDiagram;
end;
procedure TWorkflowDiagram.DoAfterExecuteNode(ANode: TCustomLiveBlock);
begin
inherited;
if ANode is TCustomWorkflowBlock then
if Assigned(WorkflowStudio.OnAfterExecuteNode) then
WorkflowStudio.OnAfterExecuteNode(WorkflowStudio, TCustomWorkflowBlock(ANode));
end;
procedure TWorkflowDiagram.DoBeforeExecuteNode(ANode: TCustomLiveBlock);
begin
inherited;
if ANode is TCustomWorkflowBlock then
if Assigned(WorkflowStudio.OnBeforeExecuteNode) then
WorkflowStudio.OnBeforeExecuteNode(WorkflowStudio, TCustomWorkflowBlock(ANode));
end;
procedure TWorkflowDiagram.DoSaveState;
begin
// if
inherited DoSaveState;
end;
procedure TWorkflowDiagram.Loaded;
begin
inherited;
SleepVisual := 0;
end;
procedure TWorkflowDiagram.LoadFromStream(AStream: TStream;
TextFormat: boolean);
var
oldName: string;
begin
if Owner <> nil then
begin
oldName := Owner.Name;
Owner.Name := wsFormName;
end;
inherited LoadFromStream(AStream, TextFormat);
if Owner <> nil then
Owner.Name := oldName;
end;
procedure TWorkflowDiagram.SaveToStream(AStream: TStream;
TextFormat: boolean);
var
oldName: string;
begin
if Owner <> nil then
begin
oldName := Owner.Name;
Owner.Name := wsFormName;
end;
inherited SaveToStream(AStream, TextFormat);
if Owner <> nil then
Owner.Name := oldName;
end;
procedure TWorkflowDiagram.SetAttachments(
const Value: TWorkflowAttachments);
begin
FAttachments.Assign(Value);
end;
procedure TWorkflowDiagram.SetVariables(const Value: TWorkflowVariables);
begin
FVariables.Assign(Value);
end;
{ TWorkflowVariables }
function TWorkflowVariables.Add: TWorkflowVariable;
begin
result := TWorkflowVariable(inherited Add);
end;
function TWorkflowVariables.FindByName(AName: string): TWorkflowVariable;
var
c: integer;
begin
result := nil;
for c := 0 to Count - 1 do
if SameText(AName, Items[c].Name) then
begin
result := Items[c];
break;
end;
end;
function TWorkflowVariables.GetItem(Index: integer): TWorkflowVariable;
begin
result := TWorkflowVariable(inherited Items[Index]);
end;
{ TWorkflowVariable }
procedure TWorkflowVariable.Assign(Source: TPersistent);
begin
if Source is TWorkflowVariable then
begin
FName := TWorkflowVariable(Source).FName;
FValue := TWorkflowVariable(Source).FValue;
end else
inherited Assign(Source);
end;
{ TWorkflowStreamDiagram }
constructor TWorkflowStreamDiagram.Create(Owner: TComponent);
begin
inherited;
SetBounds(0, 0, 0, 0);
end;
procedure TWorkflowStreamDiagram.PaintWindow(DC: HDC);
begin
end;
procedure TWorkflowStreamDiagram.WMNCPaint(var Message: TMessage);
begin
end;
{ TWorkflowAttachments }
function TWorkflowAttachments.Add: TWorkflowAttachment;
begin
result := TWorkflowAttachment(inherited Add);
end;
constructor TWorkflowAttachments.Create(AOwner: TPersistent);
begin
inherited Create(AOwner, TWorkflowAttachment);
end;
function TWorkflowAttachments.FindByName(
AName: string): TWorkflowAttachment;
var
c: integer;
begin
result := nil;
for c := 0 to Count - 1 do
if SameText(AName, Items[c].Name) then
begin
result := Items[c];
break;
end;
end;
procedure TWorkflowAttachments.MakeAllDirty;
var
c, d: integer;
begin
for c := 0 to Count - 1 do
for d := 0 to Items[c].Items.Count - 1 do
begin
Items[c].Items[d].SetContent(Items[c].Items[d].GetContent);
Items[c].Items[d].Key := '';
end;
end;
function TWorkflowAttachments.AddFile(AName: string; AFileName: string): TAttachmentItem;
var
AItem: TWorkflowAttachment;
begin
AItem := FindByName(AName);
if AItem = nil then
begin
AItem := Add;
AItem.Name := AName;
end;
result := AItem.Items.AddFile(AFileName);
end;
{ TWorkflowAttachment }
procedure TWorkflowAttachment.Assign(Source: TPersistent);
begin
if Source is TWorkflowAttachment then
begin
FName := TWorkflowAttachment(Source).FName;
FItems.Assign(TWorkflowAttachment(Source).Items);
end else
inherited Assign(Source);
end;
constructor TWorkflowAttachment.Create(Collection: TCollection);
begin
inherited Create(Collection);
FItems := TAttachmentItems.Create(Self);
end;
destructor TWorkflowAttachment.Destroy;
begin
FItems.Free;
inherited;
end;
procedure TWorkflowAttachment.SetItems(
const Value: TAttachmentItems);
begin
FItems.Assign(Value);
end;
function TWorkflowAttachments.GetItem(Index: integer): TWorkflowAttachment;
begin
result := TWorkflowAttachment(inherited Items[Index]);
end;
{ TAttachmentItems }
function TAttachmentItems.Add: TAttachmentItem;
begin
result := TAttachmentItem(inherited Add);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -