0

不知道我在这里做错了什么

//update controls from main form Tshape
 form2.cbxShape.ItemIndex:= ord(Shape1.Shape);
 form2.cbxColor.Selected:= Shape1.Brush.Color;
 form2.cbxStyle.ItemIndex:= Ord(Shape1.Brush.Style);
 if form2.ShowModal = mrOK then
 begin
  //update main form Tshape from controls
   Shape1.Shape:= TShapeType(form2.cbxShape.ItemIndex);
   Shape1.Brush.Color:= form2.cbxColor.Selected;
   Shape1.Brush.Style:= TBrushStyle(form2.cbxStyle.ItemIndex);
 end;

我没有得到正确的形状或画笔样式(颜色效果很好)

列表框项如下:

Circle
Ellipse
Rectangle
RoundRect
RoundSquare
Square

BDiagonal
Clear
Cross
DiagCross
FDiagonal
Horizontal
Solid
4

2 回答 2

5

查看TShapeTypeand的声明TBrushStyle

TShapeType = (stRectangle, stSquare, stRoundRect, stRoundSquare, stEllipse, stCircle);

TBrushStyle = (bsSolid, bsClear, bsHorizo​​ntal, bsVertical, bsFDiagonal, bsBDiagonal, bsCross, bsDiagCross);

列表框中的项目必须具有相同的顺序,包含相同的对应枚举。

于 2013-02-09T22:05:51.253 回答
1

LU RD 已经回答了这个问题。
另一种独立于任何排序的方法来达到目标​​可能是

implementation
uses TypInfo;
{$R *.dfm}

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
  SetPropValue(Shape1,'Shape','st' + Combobox1.Text);
  Caption := StringReplace(GetPropValue(Shape1,'Shape',true),'st','',[]);
end;
于 2013-02-09T23:00:12.173 回答