Доброе время суток.
Нужен тест кода в других версиях delphi.
orHigher
Вопрос:
"Хотел бы узнать на практике встречается еще у кого
вариант №2?"
У меня только D7 и Dlite - Borland® Delphi® for Microsoft® Windows™ Version 10.0.2166.28377
Update 1 Copyright © 2005 Borland® Software Corporation. All Rights
Reserved.
В D7 работает нормально.
Выглядит так
Вариант №1
https://yadi.sk/i/LxWIqIRENV1PFgВторой откомпилирован в Dlite
Вариант №2https://yadi.sk/i/yzsC23LgKOPeGAНе рабочий.
Код немного изменен Msg: tagMSG -> Msg: KOL.TMsg;
На явное указание иначе будет из Windows tagMSG тянуть.
В обоих случаях компиляции код один и тот же.
Только вот результат разный.
Спасибо.
program Test;
uses
KOL,
Unit1 in 'Unit1.pas' ;
begin
NewForm1(Form1, nil);
Run(Form1.Form);
end.
unit Unit1;
interface
uses KOL, Messages,Windows;
type
PForm1 = ^TForm1;
TForm1 = object(TObj)
Form: PControl;
ListView1:PControl;
Button1:PControl;
procedure KOLForm1FormCreate(Sender: PObj);
function ListView1LVCustomDraw(Sender: PControl; DC: HDC;
Stage: Cardinal; ItemIdx, SubItemIdx: Integer; const Rect: TRect;
ItemState: TDrawState; var TextColor, BackColor: Integer): Cardinal;
function KOLForm1Message(var Msg: KOL.TMsg; var Rslt: Integer): Boolean;
function ListView1Message(var Msg: KOL.TMsg; var Rslt: Integer): Boolean;
private
public
end;
var
Form1: PForm1;
procedure NewForm1( var Result: PForm1; AParent: PControl );
implementation
procedure NewForm1( var Result: PForm1; AParent: PControl );
begin
Result := PForm1.Create;
New( Result, Create );
Result.Form := NewForm( AParent, 'Form1' );
Applet := Result.Form;
Result.Form.Add2AutoFree( Result );
Result.Form.SetUnicode(TRUE);
Result.Form.SetName( Applet, 'Form1' );
Result.Form.Border := 8;
Result.Form.OnMessage := Result.KOLForm1Message;
Result.ListView1 := NewListView( Result.Form, lvsDetail, [ lvoMultiselect, lvoRowSelect, lvoOwnerData, lvoOwnerDrawFixed ], nil, nil, nil ).SetAlign ( caClient );
Result.ListView1.SetName( Result.Form, 'ListView1' );
Result.ListView1.SetUnicode(TRUE);
Result.ListView1.Color := clWindow;
Result.ListView1.LVColAdd( 'Column0', taLeft, 150);
Result.ListView1.LVColAdd( 'Column1', taLeft, 150);
Result.ListView1.LVColAdd( 'Column2', taLeft, 150);
Result.Button1 := NewButton( Result.Form, 'Button1' ).SetAlign ( caBottom );
Result.Button1.SetName( Result.Form, 'Button1' );
Result.Button1.SetUnicode(TRUE);
Result.ListView1.OnMessage := Result.ListView1Message;
Result.ListView1.OnLVCustomDraw := Result.ListView1LVCustomDraw;
Result.KOLForm1FormCreate( Result );
end;
procedure TForm1.KOLForm1FormCreate(Sender: PObj);
begin
ListView1.LVItemAdd( 'Item0.0' );
ListView1.LVItems[0,1]:='Item0.1';
ListView1.LVItems[0,2]:='Item0.2';
ListView1.LVItemAdd( 'Item1.0' );
ListView1.LVItems[1,1]:='Item1.1';
ListView1.LVItems[1,2]:='Item1.2';
ListView1.LVCount := 2;
end;
function TForm1.ListView1LVCustomDraw(Sender: PControl; DC: HDC;
Stage: Cardinal; ItemIdx, SubItemIdx: Integer; const Rect: TRect;
ItemState: TDrawState; var TextColor, BackColor: Integer): Cardinal;
var Txt: String;
R, R1: TRect;
procedure ProvideColors;
begin
if odsSelected in ItemState then
begin
if Sender.Focused then
begin
Sender.Canvas.Brush.Color := clNavy;
Sender.Canvas.Font.Color := clYellow;
end
else
begin
Sender.Canvas.Brush.Color := Color2RGB( clBtnFace );
Sender.Canvas.Font.Color := clRed;
end;
end
else
begin
Sender.Canvas.Brush.Color := clWindow;
Sender.Canvas.Font.Color := clBlue;
end;
Sender.Canvas.DeselectHandles;
end;
var i, j: Integer;
begin
if LongBool(Stage = (CDDS_PREPAINT or CDDS_SUBITEM)) and (ItemIdx >= 0) then
begin
Result := CDRF_SKIPDEFAULT;
R := Sender.LVItemRect( ItemIdx, lvipBounds );
if R.Bottom < 0 then Exit;
for i := 0 to ListView1.LVColCount-1 do
begin
R1 := R;
for j := 0 to i-1 do
inc( R1.Left, Sender.LVColWidth[ j ] );
R1.Right := R1.Left + Sender.LVColWidth[ i ];
Txt := 'Item' + Int2Str( ItemIdx ) + '.' + Int2Str( i );
ProvideColors;
Sender.Canvas.TextRect( R1, R1.Left, R1.Top, Txt );
end;
Sender.Canvas.Brush.Color := clWindow;
Sender.Canvas.Font.Color := clWindowText;
end
else
Result := CDRF_NOTIFYITEMDRAW;
end;
function TForm1.KOLForm1Message(var Msg: KOL.TMsg; var Rslt: Integer): Boolean;
begin
Result := FALSE;
if (Msg.message = WM_LBUTTONDOWN) and (Msg.hwnd = Form.Handle) then begin
form.Perform(WM_NCLBUTTONDOWN, HTCAPTION, Msg.lParam);
Result:= True;
end;
end;
function TForm1.ListView1Message(var Msg: KOL.TMsg;
var Rslt: Integer): Boolean;
var NMHdr: PNMHdr;
begin
Result := FALSE;
CASE Msg.message OF
WM_NOTIFY:
begin
NMHdr := Pointer( Msg.lParam );
if NMHdr.code = NM_CUSTOMDRAW then
begin
Rslt := CDRF_DODEFAULT;
Result := TRUE;
end;
end;
END;
end;
end.