?? dlcontrol.~pas
字號(hào):
unit DLControl;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DB, ADODB;
type
TDotState=(dsLink, dsBreak);
TLineState=(lsUnknown, lsOn, lsOff);
TLineList=class;
TDot = class
private
FDotState: TDotState;
FDotId: Integer;
FBDSDot: Boolean;
FLinkedLines: TLineList;
protected
Checked:Boolean;
public
constructor Create;
destructor Destroy;override;
procedure Assign(aDot:TDot);
procedure SaveToStream(Stream:TStream);
procedure LoadFromStream(Stream:TStream);
property LinkedLines:TLineList read FLinkedLines;
{節(jié)點(diǎn)編號(hào)}
property DotId:Integer read FDotId write FDotId;
{是否為變電所}
property BDSDot:Boolean read FBDSDot write FBDSDot;
{節(jié)點(diǎn)狀態(tài)}
property DotState:TDotState read FDotState write FDotState;
end;
TDotList = class
private
FList:TList;
FOwnerRec:Boolean;
function GetItemCount:Integer;
function GetItem(Index:Integer):TDot;
public
constructor Create(const bOwnerRec:Boolean);
destructor Destroy;override;
procedure Assign(Source:TDotList);
procedure Remove(aDot:TDot);
procedure Add(Value:TDot);overload;
function Add:TDot;overload;
procedure Insert(const Index:Integer;Value:TDot);overload;
function Insert(const Index:Integer):TDot;overload;
procedure Delete(const Index:Integer);
procedure Clear;
function IndexOf(const DotId:Integer):Integer;
function FindDot(const DotId:Integer):TDot;
procedure LoadFromFile(const FileName:string);
procedure SaveToFile(const FileName:string);
procedure LoadFromStream(Stream:TStream);
procedure SaveToStream(Stream:TStream);
property ItemCount:Integer read GetItemCount;
property Items[Index:Integer]:TDot read GetItem;
property OwnerRec:Boolean read FOwnerRec;
end;
TLine = class
private
FLineId: Integer;
FCurState: TLineState;
FLinkedDots: TDotList;
FOldState: TLineState;
public
constructor Create;
destructor Destroy;override;
procedure Assign(aLine:TLine);
procedure SaveToStream(Stream:TStream);
procedure LoadFromStream(Stream:TStream);
procedure GetDLFromDots(List:TDotList);
procedure SaveState;
function StateChanged:Boolean;
property LineId:Integer read FLineId write FLineId;
property OldState:TLineState read FOldState write FOldState;
property CurState:TLineState read FCurState write FCurState;
property LinkedDots:TDotList read FLinkedDots write FLinkedDots;
end;
TLineList = class
private
FList:TList;
FOwnerRec:Boolean;
function GetItemCount:Integer;
function GetItem(Index:Integer):TLine;
public
constructor Create(const bOwnerRec:Boolean);
destructor Destroy;override;
procedure Assign(Source:TLineList);
procedure Add(Value:TLine);overload;
function Add:TLine;overload;
procedure Insert(const Index:Integer;Value:TLine);overload;
function Insert(const Index:Integer):TLine;overload;
procedure Delete(const Index:Integer);
procedure Clear;
function IndexOf(const LineId:Integer):Integer;
function FindLine(const LineId:Integer):TLine;
procedure LoadFromFile(const FileName:string);
procedure SaveToFile(const FileName:string);
procedure LoadFromStream(Stream:TStream);
procedure SaveToStream(Stream:TStream);
property ItemCount:Integer read GetItemCount;
property Items[Index:Integer]:TLine read GetItem;
property OwnerRec:Boolean read FOwnerRec;
end;
TDLControl=class
private
FDots: TDotList;
FLines: TLineList;
FUnitID: Integer;
protected
{分析一條線上一個(gè)端點(diǎn)的狀態(tài),如果該端點(diǎn)的狀態(tài)為dsBreak,則證明該端點(diǎn)無法
給該線路供電,該線路也無法給和該端點(diǎn)相連的其它線路供電,該線路的供電,通
過其它端點(diǎn)控制,如果所有其它端點(diǎn)都為}
procedure AnalyzeDot(aDot:TDot; const bInput:Boolean);
public
constructor Create;
destructor Destroy;override;
{從數(shù)據(jù)庫(kù)加載整個(gè)網(wǎng)絡(luò),包括節(jié)點(diǎn)和線路}
procedure LoadFromDataBase(aQuery:TADOQuery);
{改變一個(gè)開關(guān)的狀態(tài)}
procedure SetDotState(aDot:TDot; aState:TDotState;
const bApply:Boolean);
{保存狀態(tài)到數(shù)據(jù)庫(kù)}
procedure SaveState(aDot:TDot; aQuery:TADOQuery);
{變電所是否被分析過}
function BDSNetWorkIsAnalyzed(aBDSDot:TDot):Boolean;
{取得所有變電所}
procedure GetBDSDots(List:TDotList);
{分析狀態(tài)}
procedure AnalyzeState;
property UnitID:Integer read FUnitID write FUnitID;
property Dots:TDotList read FDots;
property Lines:TLineList read FLines;
end;
implementation
uses
ADODBTools;
constructor TDotList.Create(const bOwnerRec:Boolean);
begin
inherited Create;
FList:=TList.Create;
FOwnerRec:=bOwnerRec;
end;
destructor TDotList.Destroy;
begin
Clear;
FList.Free;
inherited Destroy;
end;
function TDotList.GetItemCount:Integer;
begin
Result:=FList.Count;
end;
function TDotList.GetItem(Index:Integer):TDot;
begin
Result:=FList.Items[Index];
end;
procedure TDotList.Add(Value:TDot);
begin
FList.Add(Value);
end;
function TDotList.Add:TDot;
begin
if not FOwnerRec then
raise Exception.Create('不能創(chuàng)建記錄對(duì)象,因?yàn)榱斜聿皇撬姓撸?#039;);
Result:=TDot.Create;
Add(Result);
end;
procedure TDotList.Insert(const Index:Integer;Value:TDot);
begin
FList.Insert(Index,Value);
end;
function TDotList.Insert(const Index:Integer):TDot;
begin
if not FOwnerRec then
raise Exception.Create('不能創(chuàng)建記錄對(duì)象,因?yàn)榱斜聿皇撬姓撸?#039;);
Result:=TDot.Create;
FList.Insert(Index,Result);
end;
procedure TDotList.Delete(const Index:Integer);
begin
if FOwnerRec then
TDot(FList.Items[Index]).Free;
FList.Delete(Index);
end;
procedure TDotList.Clear;
var
i:Integer;
begin
if FOwnerRec then
for i:=0 to FList.Count-1 do
TDot(FList.Items[i]).Free;
FList.Clear;
end;
procedure TDotList.LoadFromFile(const FileName:string);
var
Stream:TMemoryStream;
begin
Stream:=TMemoryStream.Create;
try
Stream.LoadFromFile(FileName);
LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
procedure TDotList.SaveToFile(const FileName:string);
var
Stream:TMemoryStream;
begin
Stream:=TMemoryStream.Create;
try
SaveToStream(Stream);
Stream.SaveToFile(FileName);
finally
Stream.Free;
end;
end;
procedure TDotList.LoadFromStream(Stream:TStream);
var
AObj:TDot;
begin
Clear;
Stream.Position:=0;
while Stream.Position<Stream.Size do
begin
AObj:=Add;
AObj.LoadFromStream(Stream);
end;
end;
procedure TDotList.SaveToStream(Stream:TStream);
var
i:Integer;
AObj:TDot;
begin
Stream.Size:=0;
Stream.Position:=0;
for i:=0 to FList.Count-1 do
begin
AObj:=Items[i];
AObj.SaveToStream(Stream);
end;
end;
{ TDot }
procedure TDot.Assign(aDot: TDot);
begin
FDotState:=aDot.DotState;
FDotId:=aDot.DotId;
FBDSDot:=aDot.BDSDot;
FLinkedLines.Assign(aDot.LinkedLines);
end;
constructor TDot.Create;
begin
inherited Create;
FLinkedLines:=TLineList.Create(False);
end;
destructor TDot.Destroy;
begin
FLinkedLines.Free;
inherited Destroy;
end;
procedure TDot.LoadFromStream(Stream: TStream);
begin
//請(qǐng)?jiān)诖颂帉懘a
end;
procedure TDot.SaveToStream(Stream: TStream);
begin
//請(qǐng)?jiān)诖颂帉懘a
end;
constructor TLineList.Create(const bOwnerRec:Boolean);
begin
inherited Create;
FList:=TList.Create;
FOwnerRec:=bOwnerRec;
end;
destructor TLineList.Destroy;
begin
Clear;
FList.Free;
inherited Destroy;
end;
function TLineList.GetItemCount:Integer;
begin
Result:=FList.Count;
end;
function TLineList.GetItem(Index:Integer):TLine;
begin
Result:=FList.Items[Index];
end;
procedure TLineList.Add(Value:TLine);
begin
FList.Add(Value);
end;
function TLineList.Add:TLine;
begin
if not FOwnerRec then
raise Exception.Create('不能創(chuàng)建記錄對(duì)象,因?yàn)榱斜聿皇撬姓撸?#039;);
Result:=TLine.Create;
Add(Result);
end;
procedure TLineList.Insert(const Index:Integer;Value:TLine);
begin
FList.Insert(Index,Value);
end;
function TLineList.Insert(const Index:Integer):TLine;
begin
if not FOwnerRec then
raise Exception.Create('不能創(chuàng)建記錄對(duì)象,因?yàn)榱斜聿皇撬姓撸?#039;);
Result:=TLine.Create;
FList.Insert(Index,Result);
end;
procedure TLineList.Delete(const Index:Integer);
begin
if FOwnerRec then
TLine(FList.Items[Index]).Free;
FList.Delete(Index);
end;
procedure TLineList.Clear;
var
i:Integer;
begin
if FOwnerRec then
for i:=0 to FList.Count-1 do
TLine(FList.Items[i]).Free;
FList.Clear;
end;
procedure TLineList.LoadFromFile(const FileName:string);
var
Stream:TMemoryStream;
begin
Stream:=TMemoryStream.Create;
try
Stream.LoadFromFile(FileName);
LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
procedure TLineList.SaveToFile(const FileName:string);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -