我知道它是否可能,但我需要的是通过它指针访问(使用和释放)TStream变量,将一个字符串参数传递给另一个函数。
这是"不工作"我想做的事情的例子:
public class DrawGraph
{
public PlotModel MyModel { get; set; }
public DrawGraph ()
{
var plotModel = new PlotModel {};
plotModel.Title = "Test";
var xaxis = new LinearAxis {
Position = AxisPosition.Bottom
};
var yaxis = new LinearAxis {
Position = AxisPosition.Left
};
yaxis.TickStyle = OxyPlot.Axes.TickStyle.Inside;
xaxis.MinorTickSize = 20;
yaxis.TicklineColor = OxyColors.Blue;
plotModel.Axes.Add (xaxis);
plotModel.Axes.Add (yaxis);
var series1 = new LineSeries {
StrokeThickness = 3,
MarkerType = MarkerType.Circle,
MarkerSize = 4,
MarkerStroke = OxyColors.LimeGreen,
MarkerStrokeThickness = 1
};
double[,] chartValues = new double[,] {{1437041279684.0156,1.0897299999999999},{1437041339421.4324,1.0896},{1437041397111.7322,1.0897100000000002},{1437041458595.2488,1.0898599999999998},{1437041519510.7329,1.08992},{1437041578914.1306,1.08983},{1437041639357.5877,1.0895100000000002},{1437041699721.0405,1.0895299999999999},{1437041758381.3958,1.0895000000000001},{1437041818605.84,1.08954},{1437041879932.3479,1.0894400000000002},{1437041939531.7568,1.08902}};
for (int i = 0; i < chartValues.GetLength(0)/2; i++) {
series1.Points.Add (new DataPoint (chartValues[i,0],chartValues[i,1]));
}
plotModel.Series.Add (series1);
this.MyModel = plotModel;
}
}
感谢您解决此问题的任何帮助!
答案 0 :(得分:4)
TStream是一种引用类型。您的Stm
变量包含指向流对象实例的指针。您希望传递此指针值,而不是本地变量的地址。这是固定代码:
procedure TForm1.Button1Click(Sender: TObject);
var
Stm: TMemoryStream;
begin
Stm := TMemoryStream.Create;
try
Memo.Lines.SaveToStream(Stm);
Stm.Position := 0;
Memo.Clear;
Edit.Text := IntToStr(Integer(Stm));
except
Stm.Free;
raise;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Stm: TMemoryStream;
begin
Stm := Pointer(StrToInt(Edit.Text));
try
Memo.Lines.LoadFromStream(Stm);
finally
Stm.Free;
end;
end;