⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlcontrol.~pas

📁 此代码是关于mapgis的在
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
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;
    {节点编号}
    property DotId:Integer read FDotId write FDotId;
    {是否为变电所}
    property BDSDot:Boolean read FBDSDot write FBDSDot;
    {节点状态}
    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
    {分析一条线上一个端点的状态,如果该端点的状态为dsBreak,则证明该端点无法
    给该线路供电,该线路也无法给和该端点相连的其它线路供电,该线路的供电,通
    过其它端点控制,如果所有其它端点都为}
    procedure AnalyzeDot(aDot:TDot; const bInput:Boolean);
  public
    constructor Create;
    destructor Destroy;override;
   {从数据库加载整个网络,包括节点和线路}
    procedure LoadFromDataBase(aQuery:TADOQuery);
    {改变一个开关的状态}
    procedure SetDotState(aDot:TDot; aState:TDotState;
      const bApply:Boolean);
    {保存状态到数据库}
    procedure SaveState(aDot:TDot; aQuery:TADOQuery);
    {变电所是否被分析过}
    function BDSNetWorkIsAnalyzed(aBDSDot:TDot):Boolean;
    {取得所有变电所}
    procedure GetBDSDots(List:TDotList);
    {分析状态}
    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('不能创建记录对象,因为列表不是所有者!');
  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('不能创建记录对象,因为列表不是所有者!');
  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
  //请在此处写代码
end;

procedure TDot.SaveToStream(Stream: TStream);
begin
  //请在此处写代码
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('不能创建记录对象,因为列表不是所有者!');
  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('不能创建记录对象,因为列表不是所有者!');
  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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -