小编Ben*_*Ben的帖子

程序内的程序?

我在网上发现这个代码在程序中有一个程序.我不明白为什么作者会选择这样写.我注意到的是正在执行的递归函数.

他为什么不像我见过的大多数代码那样分开程序.

他的实施:

procedure XML2Form(tree : TJvPageListTreeView; XMLDoc : TXMLDocument);
var
  iNode : IXMLNode;

  procedure ProcessNode(
    Node : IXMLNode; 
    tn   : TTreeNode);
  var
    cNode : IXMLNode;
  begin
    if Node = nil then Exit;
    with Node do
    begin
      tn := tree.Items.AddChild(tn, Attributes['text']);
      tn.ImageIndex := Integer(Attributes['imageIndex']);
      tn.StateIndex := Integer(Attributes['stateIndex']);
    end;

    cNode := Node.ChildNodes.First;
    while cNode <> nil do
    begin
      ProcessNode(cNode, tn);
      cNode := cNode.NextSibling;
    end;
  end; (*ProcessNode*) 
begin
  tree.Items.Clear;
  XMLDoc.FileName := ChangeFileExt(ParamStr(0),'.XML');
  XMLDoc.Active := True;

  iNode := XMLDoc.DocumentElement.ChildNodes.First;

  while iNode <> nil …
Run Code Online (Sandbox Code Playgroud)

delphi

20
推荐指数
2
解决办法
1万
查看次数

两个TrackBar镜子

我想知道如何在trackbar1.position的相反方向上制作我的第二个trackbar.position镜像.例如.范围从1到100.

所以什么时候TrackBar1.Position := 2,然后trackbar2.Position := 99 无论轨道轨道走哪条路,我都想反映相反的方向.

到目前为止,我的代码是:(对使用密钥不感兴趣),只是鼠标交互.

Direction : string; 
Skip : boolean;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if TrackBar1.Position = TrackBar2.Position then
begin
if Direction = 'up' then   TrackBar2.Position := TrackBar2.Position + 1;
if Direction = 'down' then TrackBar2.Position := TrackBar2.Position - 1;
skip := true;
end;


if TrackBar1.Position < TrackBar2.Position then
begin 
if skip = false then
begin
TrackBar2.Position := TrackBar2.Position - 1;
Direction := 'down';
end;
end
else
begin
if skip = false then …
Run Code Online (Sandbox Code Playgroud)

delphi pascal trackbar

6
推荐指数
1
解决办法
1206
查看次数

请帮助我使用基于块的回调

我对基于块的回调不太了解.似乎有两种我知道的方法,我不知道何时应该使用一种方法,所以有人可以向我解释两者之间的差异,纠正我并给我一些提示,如果我需要的话任何.

我从stackoverflow找到了一些代码以及来自其他地方的库,所以感谢编写此代码的人.

typedef void (^MyClickedIndexBlock)(NSInteger index);
@interface YourInterface : YourSuperClass
@property (nonatomic, strong) MyClickedIndexBlock clickedIndexBlock

.m
//where you have to call the block
if (self.clickedIndexBlock != nil) {self.clickedIndexBlock(buttonIndex)};

// where you want to receive the callback
alert.clickedIndexBlock = ^(NSInteger index){NSLog(@"%d", index);};
Run Code Online (Sandbox Code Playgroud)

我对上述的理解是:

  1. MyClickedIndexBlock是NSInteger的typedef.使用名称"clickedIndexBlock"创建的属性,其类型为MyClickedIndexBlock(表示clickedIndexBlock可以是数字).

  2. 块也可以用作方法,这就是为什么我可以调用self.clickedIndexBlock(buttonIndex);

但有些东西告诉我,这种方法作为@property只支持一个参数,例如.NSInteger的.

鉴于以下方法允许多个参数.

bluetoothMe.h

typedef void (^hardwareStatusBlock)(CBPeripheral *peripheral, BLUETOOTH_STATUS status, NSError *error);

- (void)hardwareResponse:(hardwareStatusBlock)block;
Run Code Online (Sandbox Code Playgroud)

bluetoothMe.m

- (void)hardwareResponse:(hardwareStatusBlock)block {
privateBlock = [block copy]; 
}

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
NSLog(@"Did connect to peripheral: %@", peripheral);

privateBlock(peripheral, BLUETOOTH_STATUS_CONNECTED, …
Run Code Online (Sandbox Code Playgroud)

objective-c ios objective-c-blocks ios5 ios6

3
推荐指数
1
解决办法
1374
查看次数

标签 统计

delphi ×2

ios ×1

ios5 ×1

ios6 ×1

objective-c ×1

objective-c-blocks ×1

pascal ×1

trackbar ×1