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

📄 wwdbigrdtest.pas

📁 InfoPower_Studio 2007 v5.0.1.3 banben
💻 PAS
📖 第 1 页 / 共 5 页
字号:
var
  Field: TField;
  NewSize: Integer;
  NewMap: Pointer;
begin
  if FFieldCount >= MaxMapSize then
  {$ifdef wwDelphi3Up}
     RaiseGridError(STooManyColumns);
  {$else}
     GridError(STooManyColumns);
  {$endif}
  Field := DataSet.FindField(FieldName);
  Result := Field <> nil;
  if Result then
  begin
    if FFieldMapSize = 0 then
    begin
      FFieldMapSize := 8;
      GetMem(FFieldMap, FFieldMapSize * SizeOf(Integer));
    end
    else if FFieldCount = FFieldMapSize then
    begin
      NewSize := FFieldMapSize;
      Inc(NewSize, NewSize);
      if (NewSize > MaxMapSize) or (NewSize < FFieldCount) then
	NewSize := MaxMapSize;
      GetMem(NewMap, NewSize * SizeOf(Integer));
      Move(FFieldMap^, NewMap^, SizeOf(Integer) * FFieldCount);
      FreeMem(FFieldMap, SizeOf(Integer) * FFieldCount);
      FFieldMapSize := NewSize;
      FFieldMap := NewMap;
    end;
    PIntArray(FFieldMap)^[FFieldCount] := Field.Index;
{    if FGrid.useTFields then
       PIntArray(FFieldMap)^[FFieldCount] := Field.Index
    else if wwFindSelected(FGrid.Selected, Field.FieldName, AIndex) then
       PIntArray(FFieldMap)^[FFieldCount] := AIndex;}
    Inc(FFieldCount);
  end;
end;

procedure TwwGridDataLink.ActiveChanged;
begin
  FGrid.LinkActive(Active);
end;

procedure TwwGridDataLink.ClearMapping;
begin
  if FFieldMap <> nil then
  begin
    FreeMem(FFieldMap, FFieldMapSize * SizeOf(Integer));
    FFieldMap := nil;
    FFieldMapSize := 0;
    FFieldCount := 0;
  end;
end;

procedure TwwGridDataLink.Modified;
begin
  FModified := True;
end;

procedure TwwGridDataLink.DataSetChanged;
begin
  FGrid.DataChanged;
  FModified := False;
end;

procedure TwwGridDataLink.FocusControl(Field: TFieldRef);
begin
  if Assigned(Field) and Assigned(Field^) then
  begin
    FGrid.SelectedField := Field^;
    if (FGrid.SelectedField = Field^) and FGrid.AcquireFocus then
    begin
      Field^ := nil;
{      with FGrid do
      begin
         if (dgAlwaysShowEditor in Options) and (not isWWControl(SelectedIndex, 1)) and
            (not isMemoField(SelectedIndex, 1)) then
            ShowEditor;
      end}
//      FGrid.ShowEditor;
    end;
  end;
end;

procedure TwwGridDataLink.DataSetScrolled(Distance: Integer);
begin
  FGrid.Scroll(Distance);
end;

procedure TwwGridDataLink.LayoutChanged;
begin
{  if FGrid.useTFields then} FGrid.LayoutChanged;
end;

procedure TwwGridDataLink.EditingChanged;
begin
  FGrid.EditingChanged;

  { Update footer later, when encountering edit or insert mode }
  if (datasource<>nil) and  { 10/7/98 }
     ((datasource.state=dsInsert) or (datasource.state=dsEdit)) then
  begin
    FGrid.ShouldUpdateFooter:= True;
  end;
end;

procedure TwwGridDataLink.RecordChanged(Field: TField);
var OldModified: boolean;
begin
  OldModified:= FModified;
  if (Field = nil) or not FInUpdateData then
  begin
    FGrid.RecordChanged(Field);
    FModified := False;
  end;

  if (Field<>Nil) and (Dataset.State in [dsEdit, dsInsert]) then
  begin
     try
       FGrid.FieldChanged(Field);
     except
        FModified:= OldModified;
        raise;
     end;

     if (FGrid is TwwDBGrid) then TwwDBGrid(FGrid).Patch[0]:=True;
  end
end;

procedure TwwGridDataLink.UpdateData;
begin
  FInUpdateData := True;
  try
    if FModified then FGrid.UpdateData;
    FModified := False;
  finally
    FInUpdateData := False;
  end;
end;

procedure TwwGridDataLink.Reset;
begin
  if FModified then RecordChanged(nil) else begin
     if ((DataSource.DataSet.State = dsEdit) or (DataSource.DataSet.State = dsInsert)) and
	 dataSet.modified then
     begin
	 if MessageDlg(wwInternational.UserMessages.wwDBGridDiscardChanges,
		    mtConfirmation, [mbYes,mbNo], 0)<>mrYes then exit;
     end;
     Dataset.Cancel;
  end
end;

{ TwwCustomDBGrid }

(*
var
//  DrawBitmap: TBitmap;
  UserCount: Integer;

procedure UsesBitmap;
begin
   exit;
  if UserCount = 0 then
  begin
//    DrawBitmap := TBitmap.Create;
  end;
  Inc(UserCount);
end;


procedure ReleaseBitmap;
begin
  Dec(UserCount);
  if UserCount = 0 then begin
//     DrawBitmap.Free;
//     DrawBitmap:= Nil;
     EditIndicatorBitmap.Free;
     BrowseIndicatorBitmap.Free;
     InsertIndicatorBitmap.Free;
     MultiSelectBitmap.Free;
     MultiArrowBitmap.Free;
     EditIndicatorBitmap:= Nil;
     BrowseIndicatorBitmap:= Nil;
     InsertIndicatorBitmap:= Nil;
     MultiSelectBitmap := Nil;
     MultiArrowBitmap := Nil;
  end;
end;
*)

function Max(X, Y: Integer): Integer;
begin
  Result := Y;
  if X > Y then Result := X;
end;

(*
procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integer;
  const Text: string; Alignment: TAlignment; ARightToLeft: Boolean);
const
  AlignFlags : array [TAlignment] of Integer =
    ( DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
      DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
      DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX );
  RTL: array [Boolean] of Integer = (0, DT_RTLREADING);
var
  B, R: TRect;
  Hold, Left: Integer;
  I: TColorRef;
begin
  I := ColorToRGB(ACanvas.Brush.Color);
//  if GetNearestColor(ACanvas.Handle, I) = I then
  begin                       { Use ExtTextOut for solid colors }
    { In BiDi, because we changed the window origin, the text that does not
      change alignment, actually gets its alignment changed. }
    if (ACanvas.CanvasOrientation = coRightToLeft) and (not ARightToLeft) then
      ChangeBiDiModeAlignment(Alignment);
    case Alignment of
      taLeftJustify:
        Left := ARect.Left + DX;
      taRightJustify:
        Left := ARect.Right - ACanvas.TextWidth(Text) - 3;
    else { taCenter }
      Left := ARect.Left + (ARect.Right - ARect.Left) shr 1
        - (ACanvas.TextWidth(Text) shr 1);
    end;
    ACanvas.TextRect(ARect, Left, ARect.Top + DY, Text);
  end
end;
*)
Procedure wwWriteTextLines(ACanvas: TCanvas;
    const ARect: TRect; DX, DY: Integer; S: PChar; Alignment: TAlignment;
    WriteOptions: TwwWriteTextOptions);
const
  AlignFlags : array [TAlignment] of Integer =
    ( DT_LEFT or DT_EXPANDTABS or DT_NOPREFIX,
      DT_RIGHT or DT_EXPANDTABS or DT_NOPREFIX,
      DT_CENTER or DT_EXPANDTABS or DT_NOPREFIX );
  RTL: array [Boolean] of Integer = (0, DT_RTLREADING);
var
  R, DrawRect: TRect;
  Flags: integer;
  ADrawCanvas: TCanvas;
  TEMP: INTEGER;
  tempRect: TRect;
begin

//   WriteText(ACanvas, ARect, DX, DY, S, Alignment, True);
//   exit;

    ADrawCanvas:= ACanvas;

    if (ACanvas.CanvasOrientation = coRightToLeft) then
        ChangeBiDiModeAlignment(Alignment);

    with ARect do
    begin                     { brush origin tics in painting / scrolling.    }
      if Alignment=taRightJustify then
         R := Rect(DX, DY, Right - Left -2, Bottom - Top - 1) { 7/10/98 - Make width 1 less }
      else if Alignment=taLeftJustify then
         R := Rect(DX, DY, Right - Left, Bottom - Top - 1)
      else  {3/31/98 - If CenterJustify then allow DrawText to properly center text}
      begin
         if DX>=3 then
            R := Rect(2, DY, Right - Left, Bottom - Top - 1)
         else
            R := Rect(0, DY, Right - Left, Bottom - Top - 1)
      end;
      R.Left:= R.Left + ARect.Left;
      R.Right:= R.Right + ARect.Left;
      R.Top:= R.Top + ARect.Top;
      R.Bottom:= R.Bottom + ARect.Top;
    end;

    with ADrawCanvas do
    begin
      Font := ACanvas.Font;
      Font.Color := ACanvas.Font.Color;
      Brush := ACanvas.Brush;
      Brush.Style := bsSolid;
      if not (wtoTransparent in WriteOptions) then
      begin
         TempRect:= ARect;
{         TempRect.Left:= TempRect.Left - 1;
}
         FillRect(TempRect);
      end;

      SetBkMode(Handle, TRANSPARENT);
      Flags:= AlignFlags[Alignment];
      if (ACanvas.CanvasOrientation = coRightToLeft) then { 9/25/98 - Support bidi mode }
      begin
         if wtoAmpersandToUnderline in WriteOptions then
            Flags:= Flags and (not  DT_NOPREFIX);
         if wtoWordWrap in WriteOptions then
            Flags := Flags or DT_WORDBREAK;
         DrawRect:= ARect;
         DrawTextEx(Handle, PChar(s),
                      Length(s), drawrect, Flags or DT_CALCRECT, nil);
         if DrawRect.Left-DrawRect.right>Arect.Right-Arect.left then
         begin
            DrawRect.Left:= DrawRect.Right +
               Arect.Right-Arect.left;
         end;

         if DrawRect.Left<DrawRect.Right then DrawRect.Left:=DrawRect.Right;

         If Alignment =taLeftJustify then
         begin
            temp:= r.left;
            r.left:= r.right -2;
            r.right:= temp;
         end
         else if Alignment = taRightJustify then begin
            Flags:= AlignFlags[taLeftJustify] {or DT_RTLREADING};
            r.Left:= wwMin(ARect.Right-2, ARect.Left + ACanvas.TextWidth(s) + 2);
            r.Right:= ARect.Left;
         end
         else begin
            Flags:= AlignFlags[taLeftJustify] {or DT_RTLREADING};
            r.right:= ARect.Left + ((ARect.Right-ARect.Left) - (DrawRect.left-DrawRect.right)) div 2;
            r.left:= ARect.Right - ((ARect.Right-ARect.Left) - (DrawRect.left-DrawRect.right)) div 2;
         end;
      end;
      if wtoAmpersandToUnderline in WriteOptions then
         Flags:= Flags and (not  DT_NOPREFIX);

      if wtoWordWrap in WriteOptions then
         Flags := Flags or DT_WORDBREAK;

      {3/31/98 - Check to see if this is a single line edit control to
       determi

⌨️ 快捷键说明

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