📄 futils.pas
字号:
unit fUtils;
interface
uses
Windows, Classes, Graphics, StdCtrls, Grids, fDef;
type
TMAS_Procedure = procedure;
TMAS_ProcEvent = procedure of object;
{ TTextRectInfo }
PMAS_TextRectInfo = ^TTextRectInfo;
TTextRectInfo = packed record
R: TRect;
S: string;
FC: TColor;
BC: TColor;
AL: TAlignment;
TL: TTextLayout;
Transparent: Boolean;
end;
{ TCharSet }
TCharSet = set of Char;
{ ISplitStrList }
ISplitStrList = interface(IUnknown)
function sl: TStringList;
end;
{ TSplitStrList }
TSplitStrList = class(TInterfacedObject, ISplitStrList)
protected
FClearObjectOnFree: Boolean;
L: TStringList;
function sl: TStringList;
public
constructor Create(CVS: string; Sorted: Boolean = False; ClearObjectOnFree:
Boolean = False);
destructor Destroy; override;
end;
{ TStockFileRec }
PStockFileRec = ^TStockFileRec;
TStockFileRec = packed record
ID: string[7];
Name: string[10];
Market: Byte;
Kind: Byte;
Sector: Byte;
DealTime: TDateTime;
Ref: Single; //参考值
Bid: Single;
Ask: Single;
Deal: Single;
Diff: Single;
Open: Single;
High: Single;
Low: Single;
Vol: Single;
end;
{ TPriceState }
TPriceState = (psCeil, psUp, psEven, psDown, psFloor, psNonTrade);
{ TStock }
//股票类
TStock = class(TPersistent)
private
function GetID: string; //股票号
function GetKey: string;
function GetName: string; //股票名
protected
FRec: TStockFileRec; //股票交易数据
public
constructor Create(Rec: TStockFileRec);
function Ceil: Single; //涨停参考值
function DealState: TPriceState;
function DiffPercentage: Single;
function Floor: Single; //下限参考值
function HiLoRange: Single; //上下涨幅
function PriceState(Price: Single): TPriceState;
function psBC(Price: Single): TColor;
function psFC(Price: Single): TColor;
property ID: string read GetID; //股票号
property Key: string read GetKey;
property Name: string read GetName; //股票名
property Rec: TStockFileRec read FRec write FRec; //股票交易数据
end;
const
FILTER_KEY_STKIDNAME = '<td align=center bgcolor=#FFFfff nowrap><a href=/q/q_';
FILTER_KEY_STKDATA = '<td align="center" bgcolor="#FFFfff" nowrap>';
PSFC_COLOR: array[TPriceState] of TColor = (clYellow, clRed, clBlack, clGreen, clWhite, clBlack);
PSBC_COLOR: array[TPriceState] of TColor = (clRed, clBtnFace, clBtnFace, clBtnFace, clGreen, clBtnFace);
implementation
uses SysUtils, Math, UCommon;
{ TSplitStrList }
{
******************************** TSplitStrList *********************************
}
constructor TSplitStrList.Create(CVS: string; Sorted: Boolean = False;
ClearObjectOnFree: Boolean = False);
begin
inherited Create;
FClearObjectOnFree := ClearObjectOnFree;
L := _split_(CVS, ',');
if Sorted then
L.Sorted := True;
end;
destructor TSplitStrList.Destroy;
begin
_free_(L, FClearObjectOnFree);
inherited;
end;
function TSplitStrList.sl: TStringList;
begin
Result := L;
end;
{ TStock }
{
************************************ TStock ************************************
}
constructor TStock.Create(Rec: TStockFileRec);
begin
inherited Create;
FRec := Rec;
end;
function TStock.Ceil: Single;
begin
Result := RoundStkPrice(FRec.Ref * 1.07, False);
end;
function TStock.DealState: TPriceState;
begin
Result := PriceState(FRec.Deal);
end;
function TStock.DiffPercentage: Single;
begin
if FRec.Ref > 0 then
Result := FRec.Diff / FRec.Ref * 100
else Result := 0;
end;
function TStock.Floor: Single;
begin
Result := RoundStkPrice(FRec.Ref * 0.93);
end;
function TStock.GetID: string;
begin
Result := Trim(FRec.ID);
end;
function TStock.GetKey: string;
begin
with FRec do
begin
Result := Format('%2.2d%2.2d%2.2d%6s', [Market, Kind, Sector, Trim(ID)]); // 仿真交易所顺序
end;
end;
function TStock.GetName: string;
begin
Result := Trim(FRec.Name);
end;
function TStock.HiLoRange: Single;
begin
//股票最小值>0且有最大值
//范围为(Max-Min)/Min的百分数
if (FRec.Low > 0) and (FRec.High > FRec.Low) then
begin
Result := FRec.High / FRec.Low * 100 - 100
end
else
Result := 0;
end;
function TStock.PriceState(Price: Single): TPriceState;
begin
if Price * FRec.Ref = 0 then
Result := psNonTrade
else if (Ceil = Floor) then
Result := psNonTrade
else if Price > (Ceil - 0.0001) then
Result := psCeil
else if Price < (Floor + 0.0001) then
Result := psFloor
else if Price > FRec.Ref then
Result := psUp
else if Price < FRec.Ref then
Result := psDown
else
Result := psEven;
end;
function TStock.psBC(Price: Single): TColor;
begin
Result := PSBC_COLOR[PriceState(Price)];
end;
function TStock.psFC(Price: Single): TColor;
begin
Result := PSFC_COLOR[PriceState(Price)];
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -